Skip to content

[metadata prespecialization] Cross-module: structs and enums. #32354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

nate-chandler
Copy link
Contributor

@nate-chandler nate-chandler commented Jun 12, 2020

Initial support for cross-module metadata prespecialization.

Before, given a module

M:
struct K {}
struct G<T> {}
prespecialize( G<K>.self )

(1) canonical prespecialized metadata for G<K> was defined within M

`canonical specialized generic type metadata for G<K>` = linkonce_odr hidden constant ...

(2) it was referred to directly where it was used

prespecialize(instance, &`canonical specialized generic type metadata for G<K>`)

and (3) it was returned from the metadata accessor for G

MetadataResponse `metadata accessor for G`(MetadataRequest request, Metadata *type) {
    if (type == &`type metadata for K`) {
        return `canonical specialized generic type metadata for G<K>`
    }
    return swift_getGenericMetadata(request, {type}, `nominal type descriptor for G`)
}

In particular, note that the prespecialization for G<K> had to be done within the module which defined G.

Here, support is added for creating a prespecialization in a module different from that which defines the type. Given modules

M:
struct G<T> {}
N:
import M
struct K {}
prespecialize( G<K>.self )

(1) a non-canonical prespecialized metadata for G<K> is defined within N

`noncanonical specialized generic type metadata for G<K>` = linkonce_odr hidden constant ...

and (2) it is not referred to directly from where it is used but rather passed through the new runtime function swift_getCanonicalSpecializedMetadata

prespecialize(instance, swift_getCanonicalSpecializedMetadata(&`noncanonical specialized generic type metadata for G<K>`, &`cache variable for noncanonical specialized generic type metadata for M.G<N.K>`))

The runtime call is necessary because it can't be statically guaranteed that metadata for the type described by the noncanonical prespecialization has not been created dynamically (or provided by a different noncanonical prespecialization). That might occur, for example, in the following way:

M:
func instantiate<T>(for t: T.Type) -> G<T> { ... }

N:
instantiate(K.self)
prespecialize( G<K>.self )

In this example, instantiate would be called before noncanonical specialized generic type metadata for G<K> is passed to swift_getCanonicalSpecializedMetadata. Consequently, a metadata record for G<K> would be created dynamically and added to the runtime generic metadata cache. The invariant that there only be a single, canonical metadata record for the type G<K> must be preserved. As a result, the dynamically created metadata for G<K> must be passed to prespecialize. The new runtime call ensures that: the dynamically created metadata for G<K> will be returned from

swift_getCanonicalSpecializedMetadata(&`noncanonical specialized generic type metadata for G<K>`, &`cache variable for noncanonical specialized generic type metadata for M.G<N.K>`)

Dependent on #32506

@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 738f6827280d907ef2f9273e2406b83e9bdc3643

@nate-chandler nate-chandler force-pushed the generic-metadata-prespecialization-components/crossmodule-structs-enums branch from 738f682 to 8fa0926 Compare June 12, 2020 23:19
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler
Copy link
Contributor Author

@swift-ci please benchmark

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 738f6827280d907ef2f9273e2406b83e9bdc3643

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 738f6827280d907ef2f9273e2406b83e9bdc3643

@swift-ci
Copy link
Contributor

Performance: -O

Regression OLD NEW DELTA RATIO
FlattenListLoop 1634 2464 +50.8% 0.66x (?)
FlattenListFlatMap 5354 6638 +24.0% 0.81x (?)
ArrayInitFromSlice 447 519 +16.1% 0.86x (?)
DictionaryBridgeToObjC_Access 762 866 +13.6% 0.88x (?)

Code size: -O

Performance: -Osize

Regression OLD NEW DELTA RATIO
StringBuilderWithLongSubstring 1710 2000 +17.0% 0.86x (?)
UTF8Decode_InitFromCustom_contiguous_ascii_as_ascii 382 432 +13.1% 0.88x (?)
UTF8Decode_InitFromCustom_noncontiguous_ascii_as_ascii 1128 1265 +12.1% 0.89x (?)
StringBuilderLong 1430 1550 +8.4% 0.92x (?)
DictionaryOfAnyHashableStrings_lookup 4032 4368 +8.3% 0.92x (?)
 
Improvement OLD NEW DELTA RATIO
DataAppendArray 4400 4100 -6.8% 1.07x (?)

Code size: -Osize

Performance: -Onone

Regression OLD NEW DELTA RATIO
UTF8Decode_InitFromCustom_contiguous_ascii 347 397 +14.4% 0.87x (?)
DictionaryCompactMapValuesOfCastValue 53730 60696 +13.0% 0.89x (?)
ArrayInitFromSlice 504 562 +11.5% 0.90x (?)
UTF8Decode_InitDecoding_ascii 329 365 +10.9% 0.90x (?)
ArrayPlusEqualThreeElements 6260 6910 +10.4% 0.91x (?)
UTF8Decode_InitFromCustom_contiguous_ascii_as_ascii 426 465 +9.2% 0.92x (?)

Code size: -swiftlibs

How to read the data The tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.

If you see any unexpected regressions, you should consider fixing the
regressions before you merge the PR.

Noise: Sometimes the performance results (not code size!) contain false
alarms. Unexpected regressions which are marked with '(?)' are probably noise.
If you see regressions which you cannot explain you can try to run the
benchmarks again. If regressions still show up, please consult with the
performance team (@eeckstein).

Hardware Overview
  Model Name: Mac Pro
  Model Identifier: MacPro6,1
  Processor Name: 12-Core Intel Xeon E5
  Processor Speed: 2.7 GHz
  Number of Processors: 1
  Total Number of Cores: 12
  L2 Cache (per Core): 256 KB
  L3 Cache: 30 MB
  Memory: 64 GB

@nate-chandler
Copy link
Contributor Author

@swift-ci please clean test os x platform

@nate-chandler nate-chandler force-pushed the generic-metadata-prespecialization-components/crossmodule-structs-enums branch from 8fa0926 to 9606f82 Compare June 15, 2020 22:42
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 8fa0926303b7ec0d94516bb7626e459771ae84b9

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 8fa0926303b7ec0d94516bb7626e459771ae84b9

@nate-chandler
Copy link
Contributor Author

@swift-ci please clean test os x platform

@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 9606f8211eaadd6d92012d8c6bff77acebb0ff3d

@nate-chandler
Copy link
Contributor Author

@swift-ci please test os x platform

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 9606f8211eaadd6d92012d8c6bff77acebb0ff3d

@nate-chandler
Copy link
Contributor Author

@swift-ci please clean test os x platform

@nate-chandler nate-chandler force-pushed the generic-metadata-prespecialization-components/crossmodule-structs-enums branch from 9606f82 to 8a5d138 Compare June 17, 2020 20:08
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 9606f8211eaadd6d92012d8c6bff77acebb0ff3d

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 9606f8211eaadd6d92012d8c6bff77acebb0ff3d

@nate-chandler nate-chandler force-pushed the generic-metadata-prespecialization-components/crossmodule-structs-enums branch from 8a5d138 to 385e345 Compare June 17, 2020 23:47
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 8a5d138bd762285fe21f6149cf88229203ccd537

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 8a5d138bd762285fe21f6149cf88229203ccd537

@nate-chandler nate-chandler force-pushed the generic-metadata-prespecialization-components/crossmodule-structs-enums branch from 385e345 to 6d8bbd9 Compare June 18, 2020 19:13
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 385e34536a356db6534145b40b9941034726def0

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 6d8bbd9701be1e94507d282c8d14cda365b8709a

@nate-chandler
Copy link
Contributor Author

@swift-ci please clean test os x platform

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 22e9c2d8e71ea5b52d79a5789fbeeb02f37a798e

@nate-chandler
Copy link
Contributor Author

@swift-ci please clean test os x platform

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 22e9c2d8e71ea5b52d79a5789fbeeb02f37a798e

@nate-chandler
Copy link
Contributor Author

@swift-ci please clean test os x platform

@nate-chandler nate-chandler force-pushed the generic-metadata-prespecialization-components/crossmodule-structs-enums branch from 22e9c2d to 52f39c9 Compare June 22, 2020 19:57
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 22e9c2d8e71ea5b52d79a5789fbeeb02f37a798e

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 22e9c2d8e71ea5b52d79a5789fbeeb02f37a798e

@nate-chandler nate-chandler force-pushed the generic-metadata-prespecialization-components/crossmodule-structs-enums branch 2 times, most recently from f8ed98a to 7e273e7 Compare June 23, 2020 03:37
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 52f39c9fac2ffb4d930ec8db4ce1274df6c469f1

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 52f39c9fac2ffb4d930ec8db4ce1274df6c469f1

@nate-chandler nate-chandler marked this pull request as ready for review June 23, 2020 18:10
@nate-chandler nate-chandler force-pushed the generic-metadata-prespecialization-components/crossmodule-structs-enums branch from 7e273e7 to 48834a5 Compare July 16, 2020 19:32
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 7e273e7062a8ffa1b5d20e2dc367af6c68a1330c

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 48834a50c93a680a901b1c628953fbc734e07e2a

When a generic type from a different module is not resilient within the
current module and at least one of its arguments is from the current
module, emit a non-canonical prespecialized record, and access that
metadata via a call to swift_getCanonicalSpecializedMetadata, passing in
the non-canonical record.

rdar://problem/56996727
rdar://problem/56997022
@nate-chandler nate-chandler force-pushed the generic-metadata-prespecialization-components/crossmodule-structs-enums branch from 48834a5 to d4b82ba Compare July 16, 2020 21:14
@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 48834a50c93a680a901b1c628953fbc734e07e2a

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 48834a50c93a680a901b1c628953fbc734e07e2a

@nate-chandler
Copy link
Contributor Author

@swift-ci please clean test macos

@nate-chandler
Copy link
Contributor Author

@swift-ci please test windows

@nate-chandler
Copy link
Contributor Author

@swift-ci please test source compatibility

@nate-chandler nate-chandler merged commit 98253ae into swiftlang:master Jul 21, 2020
@nate-chandler nate-chandler deleted the generic-metadata-prespecialization-components/crossmodule-structs-enums branch July 21, 2020 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants