Commit Graph

1076 Commits

Author SHA1 Message Date
Doug Gregor f9c34756ef Parameterize conformance lookup on whether "missing" conformances are allowed.
Many clients of the conformance lookup operations would prefer to get
an invalid conformance (== there is no conformance) rather than a
missing conformance. Parameterize the conformance lookup operations so
that most callers won't see missing conformances, by filtering them
out at the end. Opt-in those callers that do want to see missing
conformances so they can be diagnosed.
2021-08-03 00:10:45 -07:00
Doug Gregor de44396bd2 Always enable "missing" conformances to Sendable.
Always build the conformances, and produce warnings/errors when they are
needed during type checking.
2021-08-02 16:17:00 -07:00
Doug Gregor c79fa23339 Implicitly build "missing" conformances to Sendable.
When looking up a conformance to Sendable fails, implicitly create a
"missing" builtin conformance. Such conformances allow type checking
to continue even in the presence of Sendable-related problems.

Diagnose these missing conformances when they are used in an actual
program, as part of availability checking for conformances and when we
are determining Sendability. This allows us to decide between an
error, a warning, and suppressing the diagnostic entirely without
affecting how the program is compiled. This is a step toward enabling
selective enforcement of Sendable.

Part of rdar://78269348.
2021-08-02 16:16:59 -07:00
Doug Gregor 3253a4fc1c [SE-0302] Implement structural conformances to Sendable.
Add implement conformance of structural types to Sendable as appropriate:
* A tuple type is Sendable when its element types are Sendable
* A metatype type is Sendable
* A function type is Sendable if it is @Sendable, thin, or C
* A builtin type is always Sendable

Implements rdar://76836578.
2021-07-28 07:38:55 -07:00
Ben Barham f1c45de2a9 [NFC] Refactor getRenameDecl to use the request evaluator
Move `getRenameDecl` from `PrintAsObjC` into its own request so that
other components can re-use this functionality.
2021-07-24 10:00:02 +10:00
Robert Widmann cc246db38f Fix Potential Use-After-Free of Temporary Twine
Twine is non-owning and the lifetime of the result ends at the semicolon
here unless it is consumed into an owning abstraction. Convert to
a std::string first then insert that into the buffer here.

Not a big deal since this is along a catastrophic error path.
2021-07-21 14:58:12 -07:00
Doug Gregor 9c8615d663 Revert "Disable standard substitutions when building with "older" _Concurrency module" 2021-06-16 23:07:08 -07:00
Doug Gregor de8c8f5537 Disable standard substitutions when building with "older" _Concurrency module
To smooth over an ABI transition, disable the standard substitutions
for the _Concurrency module within the AST mangler when the
_Concurrency module we are using predates custom executors. This is a
short-term hack that should be removed when we settle the ABI.

Addresses rdar://79298287.
2021-06-15 09:37:34 -07:00
Slava Pestov a250688a50 AST: Use availability to disambiguate multiple overlapping conformances
If a conformance is found in an imported module as well as the current module,
and one of the two conformances is conditionally unavailable on the current
deployment target, pick the one that is always available.

Fixes <rdar://problem/78633800>.
2021-06-07 00:45:59 -04:00
Doug Gregor b57a73ab42 [Concurrency ABI] Add standard substitutions for _Concurrency types.
Introduce a second level of standard substitutions to the mangling,
all of the form `Sc<character>`, and use it to provide standard
substitutions for most of the _Concurrency types.

This is a precursor to rdar://78269642 and a good mangling-size
optimization in its own right.
2021-06-01 17:15:02 -07:00
Hamish Knight ed104a8134 Merge pull request #37014 from hamishknight/entry-sign 2021-05-19 08:32:40 +01:00
Erik Eckstein 762e9c7882 Serialization: serialize if the module is a static library
If the `-static` option is specified, store that in the generated
swiftmodule file.  When de-serializing, recover this information in the
representative SILModule.

This will be used for code generation on Windows.  It is the missing
piece to allow static linking to function properly.  It additionally
opens the path to additional optimization on ELF-ish targets - GOT, PLT
references can be avoided when the linked module is known to be static.

Co-authored by: Saleem Abdulrasool <compnerd@compnerd.org>
2021-05-02 09:34:52 -07:00
Ben Barham 0fc005dd8e Merge pull request #37105 from bnbarham/serialize-offsets
[Serialization] Store offset of decls in .swiftsourceinfo
2021-04-29 16:37:15 +10:00
Ben Barham c763ab5d1e [Serialization] Store offset of decls in .swiftsourceinfo
The locations stored in .swiftsourceinfo included the presumed file,
line, and column. When a location is requested it would read these, open
the external file, create a line map, and find the offset corresponding
to that line/column.

The offset is known during serialization though, so output it as well to
avoid having to read the file and generate the line map.

Since the serialized location is returned from `Decl::getLoc()`, it
should not be the presumed location. Instead, also output the line
directives so that the presumed location can be built as per normal
locations.

Finally, move the cache out of `Decl` and into `ASTContext`, since very
few declarations will actually have their locations deserialized. Make
sure to actually write to that cache so it's used - the old cache was
never written to.
2021-04-29 12:33:05 +10:00
Robert Widmann 43a9f54b0f Repair Fingerprint Lookup Across Modules
Cross-module incremental builds require a stable source of fingerprint
information for iterable decl contexts. This is provided by the
incremental frontends when they produce partial swift module files.
Embedded in these files is a table of fingerprints, which are consumed
by merge-modules to construct a module-wide dependency graph that is
then serialized into the final merged swift module file. Unfortunately,
the implementation here iterated through the files in the module and
asked for the first fingerprint that would load for a particular
iterable decl context. If (more likely, when) the DeclID for that
serialized iterable decl context collided with another DeclID in the
wrong file, we would load that fingerprint instead.

Locate up to the module-scope context for an iterable decl context and
only load the fingerprint from there. This ensures that the fingerprints
in the partial modules matches the fingerprints in the merged modules.

rdar://77005039
2021-04-27 21:39:25 -07:00
Hamish Knight 272090752b [AST] Upgrade MainDecl to a ValueDecl
This will make it easier to store in a SILDeclRef.
2021-04-26 11:42:31 +01:00
Ben Barham 52de30ce1f [Gardening] Do not store start/end line in SingleRawComment
The start and end lines were only used while constructing the comments,
so move the line tracking into that method instead of storing it in each
comment.
2021-04-16 08:10:49 +10:00
Ben Barham c54c9c7079 [Gardening] Extract basic source info structs from RawComment.h 2021-04-14 10:05:27 +10:00
Alexis Laferrière 6bbb9f04da [Sema] Only look for PrivateFrameworks on Darwin 2021-03-26 16:33:09 -07:00
Alexis Laferrière f1f015c7dc [Sema] Use path::append in ModuleLibraryLevelRequest 2021-03-26 16:30:15 -07:00
Alexis Laferrière cf58bb7eb4 [Sema] Report public imports of private modules
Intro the concept of library access or distribution level to identify
layers of libraries and report public imports of private libraries from
public ones.

rdar://62934005
2021-03-26 16:30:15 -07:00
nate-chandler 64c75828f7 Merge pull request #36529 from nate-chandler/rdar75547146
Sema: Stop checking @main if no decl synthesized.
2021-03-23 08:04:40 -07:00
Nate Chandler 6c5d62c011 Sema: Stop checking @main if no decl synthesized.
When requestifying the synthesis of the main function for the type
annotated @main via SynthesizeMainFunctionRequest, what were previously
were bailouts from AttributeChecker::visitMainTypeAttr had to become
returns of nullptr from SynthesizeMainFunctionRequest::evaluate.
Consequently, AttributeChecker::visitMainTypeAttr must check whether
synthesis actually succeeded before proceeding to to register the main
decl for a file.

In simple cases, this happened to work because
SourceFile::registerMainDecl would return early if the decl being
registered was the same as the already registered main decl and in
particular if the decl being registered was nullptr and the previously
registered one was nullptr as well.  When, however, there are multiple
types annotated @main, if a function is successfully synthesized for one
type but synthesis fails for the second, an attempt will be made to
register nullptr as the main decl and will move past the check at the
beginning of SourceFile::registerMainDecl, resulting in a crash.

Here, we bail from AttributeChecker::visitMainTypeAttr if function
synthesis fails and add an assert to SourceFile::registerMainDecl that
the provided decl is non-null.

rdar://75547146
2021-03-19 16:54:16 -07:00
Doug Gregor 9579390024 [SE-0304] Rename ConcurrentValue to Sendable 2021-03-18 22:48:20 -07:00
Doug Gregor 6ed794d188 Bake the _Concurrency -> Swift ABI module name into the compiler.
Using `-module-abi-name` for the `_Concurrency` module breaks older
Swift compilers. Instead, hard-code that "Swift" is the ABI name of the
"_Concurrency" module in the compiler to dodge the problem.
2021-03-12 11:21:46 -08:00
Doug Gregor 71b7c92453 Handle more cycles with ConcurrentValue inference 2021-03-02 12:09:14 -08:00
Doug Gregor b5e4b085aa Infer ConcurrentValue conformances for structs and enums.
When a struct or enum has only ConcurrentValue-conforming instance
data, infer conformance to ConcurrentValue.
2021-03-02 00:23:33 -08:00
David Ungar 90ee114b4a add fingerprint excluding to basic source file info 2021-02-26 17:20:44 -08:00
Rintaro Ishizaki bb45b2a822 [CodeCompletion] Lazily populate 'BasicSourceFileInfo' 2021-02-25 14:56:55 -08:00
David Ungar 6e034cac4e Revert "[NFC; Incremental] Rename BasicSourceFileInfo.InterfaceHash" 2021-02-25 09:06:53 -08:00
David Ungar cbd92e65ff Rename BasicSourceFileInfo.InterfaceHash 2021-02-24 09:13:22 -08:00
Holly Borla 11028350a7 Merge pull request #35589 from Jumhyn/placeholder-types
[AST, Sema] Replace HoleType with PlaceholderType
2021-02-22 08:35:37 -08:00
Doug Gregor 66cd7d82ae Marker protocols are self-conforming. 2021-02-18 23:44:39 -08:00
Frederick Kellison-Linn a5d0153fbf [AST] Assume that placeholder types conform to all protocols 2021-02-16 22:59:19 -05:00
Becca (née Brent) Royal-Gordon e6aee251be Merge pull request #35904 from beccadax/go-back-to-the-shadow
Warn about module name shadowing in interfaces
2021-02-16 15:32:41 -08:00
AG a5b804602d Merge pull request #35110 from bitjammer/acgarland/emit-symbol-graph
Add optional -emit-symbol-graph output when emitting modules
2021-02-12 09:00:58 -08:00
Becca Royal-Gordon c2f3725f56 Warn about module name shadowing in interfaces
There is a known issue with module interfaces where a type with the same name as a module will disrupt references to types in that module. Fully fixing it will require a new language feature (SR-898) which is not yet available. In the meantime, module interfaces support a workaround flag (“-Xfrontend -module-interface-preserve-types-as-written”) which prints an alternate form that usually works. However, you have to know to add this flag, and it’s not obvious because nothing breaks until a compiler tries to consume the affected module interface (or sometimes even one of its clients).

This commit emits a warning during module interface emission whenever the module interface either imports a type with the same name as the module being built, or declares a type with the same name as a visible module. This lets the user know that the type may cause problems and they might need to implement a workaround.
2021-02-10 19:03:06 -08:00
Robert Widmann b960c6e31c Derive a Fingerprint from a Module's BasicSourceFileInfo 2021-02-02 09:57:46 -08:00
Robert Widmann 7c5f8a0e6c [NFC] Const-qualify BasicSourceFileInfo 2021-02-02 09:57:04 -08:00
Ashley Garland 69c4fc47cb Add optional -emit-symbol-graph output when emitting modules
rdar://71497047
2021-01-28 09:55:33 -08:00
Robert Widmann 73ac8d3531 Replace llvm::MD5 with StableHasher 2021-01-21 17:19:38 -08:00
Erik Eckstein e3d636e519 CrossModuleOptimization: fix crash when importing a module as implementationOnly
If a function uses a type imported as implementationOnly (or similar), it cannot be serialized.

I added a new API in ModuleDecl (canBeUsedForCrossModuleOptimization), which performs this check.

rdar://72864719
2021-01-18 13:09:27 +01:00
Ben Barham b6aedc75f8 Merge pull request #35441 from bnbarham/allow-delayed-parsing-with-interface-hash
[Parser] Keep delayed body parsing even with interface hash generation
2021-01-16 13:25:38 +10:00
Ben Barham 4be504673e [Parser] Keep delayed body parsing even with interface hash generation
The generated hash ignores tokens parsed in the body anyway, so there's
no reason to disable delayed body parsing in this case.
2021-01-15 10:17:12 +10:00
Rintaro Ishizaki a9a044c6e3 [Serialization] Serialize fingerprint, mtime, size of the source files 2021-01-13 11:49:52 -08:00
Rintaro Ishizaki 09121f7780 [AST] Move getInterfaceHashIncludingTypeMembers() to SourceFile 2021-01-13 11:49:52 -08:00
Rintaro Ishizaki 1b6e7857c2 [Serialization] Serialize/deserialize source file list 2021-01-13 11:49:52 -08:00
Slava Pestov d1a2a612b1 AST: Change some writeDependencySink() methods to take the result by const reference 2020-12-22 01:42:04 -05:00
Arnold Schwaighofer 2b6ba2830c Serialize decls with _specialize(exported:true, target: somefunc(_:), ...) in a list for fast lookup
rdar://71430641
2020-12-11 09:58:32 -08:00
Robert Widmann 883902411b Migrate loadFingerprint onto ModuleDecl and Friends 2020-11-18 12:20:14 -08:00