Commit Graph

944 Commits

Author SHA1 Message Date
Holly Borla
6fcd3f6557 [Macros] Enable composition of member attribute macros and accessor macros. 2023-01-17 18:54:16 -08:00
Erik Eckstein
bfa14e64dd Revert "[Macros] Enable composition of member attribute macros and accessor macros."
It causes crashes in some Sema/SwiftUI tests in some configurations.

rdar://104297642

This reverts commit b8d65e1ed9.
2023-01-17 13:30:27 +01:00
Holly Borla
b8d65e1ed9 [Macros] Enable composition of member attribute macros and accessor macros. 2023-01-15 10:11:00 -08:00
Doug Gregor
ab4ecc390d Allow empty lists of files when looking up files containing a source location 2023-01-08 19:17:39 -08:00
Pavel Yaskevich
5afccec917 [AST] RuntimeMetadata: Register all decls with runtime discoverable attrs that appear in a file
This would make it really easy to generate SIL/IR for all of the
declarations in the given file that have runtime discoverable attributes.
2022-12-20 09:33:44 -08:00
Doug Gregor
f467ef4d37 [Source manager] Start tracking generated-source info in the source manager
Establish the relationship for generated sources, whether for macro
expansions or (via a small stretch) replacing function bodies with
other bodies, in the source manager itself. This makes the information
available for diagnostic rendering, and unifies a little bit of the
representation, although it isn't used for much yet.
2022-12-14 23:02:27 -08:00
Alexis Laferrière
bddd1976f3 Merge pull request #62353 from xymus/dont-index-local-system-modules
[Index] Only index system modules in the SDK, not local ones
2022-12-13 09:35:43 -08:00
Alex Hoppen
fe2ae72ad2 [IDE] Rename CodeCompletion to IDEInspection in cases where the code path no longer exclusively applies to code completion
The code completio infrastructure is also being used for cursor info now, so it should no longer be called code completion.

rdar://103251187
2022-12-13 11:41:05 +01:00
Alexis Laferrière
03708d2a06 [AST] Rework isSDKModule with a different algorithm 2022-12-12 16:08:48 -08:00
Alexis Laferrière
14c639b549 [Index] Index only system modules in the SDK
Indexing a module from the swiftinterface puts the swiftinterface
version in the cache. Subsequent builds don't see the adjacent
swiftmodule file. This can break test clients that need the adjacent
swiftmodule information. To avoid this scenario, ensure that we only
index system modules in the SDK, not local versions.

rdar://102207620
2022-12-07 13:27:08 -08:00
Xi Ge
afbc4a5ffd Merge pull request #62251 from nkcsgexi/allowable-serialization
serialization: encode allowable client names in binary module format
2022-11-28 18:12:43 -08:00
Alexis Laferrière
c266e9dce5 Merge pull request #62185 from xymus/improve-rmodule-loading
Improve `-Rmodule-loading` to show both the path to the source and to the cached file actually loaded
2022-11-28 14:25:15 -08:00
Xi Ge
5987654b3a Merge branch 'main' into allowable-serialization 2022-11-28 09:36:04 -08:00
Xi Ge
c3db946517 sema: diagnose importation from disallowed modules 2022-11-25 23:37:01 -08:00
Erik Eckstein
ab1b343dad use new llvm::Optional API
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.

rdar://102362022
2022-11-21 19:44:24 +01:00
Alexis Laferrière
319d49816d [Frontend] -Rmodule-loading shows both source path and cached path 2022-11-18 15:28:16 -08:00
Robert Widmann
4c162b2aeb Delete libSyntax 2022-11-16 14:52:28 -08:00
Holly Borla
2c067749a3 Merge pull request #62113 from apple/revert-62075-implicit-some-type-reconstruction
Revert "[Sema] Record opaque type decls for type reconstruction after creation instead of in the parser."
2022-11-15 12:35:56 -08:00
Alexis Laferrière
f7414ed41c Merge pull request #62102 from xymus/spi-reexported-export-as
[Sema] Restrict reexported SPIs to modules with an `export_as` relationship
2022-11-15 09:15:34 -08:00
Holly Borla
2213a02aaa Revert "[Sema] Record opaque type decls for type reconstruction after creation instead of in the parser." 2022-11-15 08:44:01 -08:00
Alexis Laferrière
552d3a4984 [Sema] Restrict reexported SPIs to modules with an export_as relationship
@_exported exports SPIs only when the exported module defines export_as
pointing to the exporter module. Other reexports do not reexport SPIs.
This is to prevent SPI reexporting to get out of hands with the wide
reexports of the Objective-C world.

rdar://102335473
2022-11-14 13:17:55 -08:00
Alexis Laferrière
e52fbb89c1 [AST] Intro a check for the export_as relationship between 2 modules 2022-11-14 12:28:31 -08:00
Holly Borla
14f11715ba Merge pull request #62075 from hborla/implicit-some-type-reconstruction
[Sema] Record opaque type decls for type reconstruction after creation instead of in the parser.
2022-11-12 11:31:12 -08:00
Holly Borla
33f5c1040d [Sema] Record opaque type decls for type reconstruction in OpaqueResultTypeRequest
instead of in the parser.
2022-11-11 18:31:47 -08:00
Alexis Laferrière
c0abde01a2 [Sema] @_exported imports export @_spi decls too
Enable transitive imports of all SPI groups through @_exported imports.
This brings to SPI the same behavior that we have for API.

```
// Module A
@_spi(S) public func foo() {}

// Module B
@_exported import A

// Module C
@_spi(S) import B

foo() // SPI imported through the reexport of A from B
```

rdar://101566534
2022-11-10 16:46:14 -08:00
Alexis Laferrière
3ca1de0a0f [Sema] Clean up lookupImportedSPIGroups 2022-11-08 16:35:43 -08:00
Doug Gregor
0f30950fde Introduce an LRU cache for getSourceFileContainingLocation(). 2022-11-01 10:09:02 -07:00
Doug Gregor
0f9a70601a Parse and record top-level "items" rather than always forcing declarations.
In the Swift grammar, the top-level of a source file is a mix of three
different kinds of "items": declarations, statements, and expressions.
However, the existing parser forces all of these into declarations at
parse time, wrapping statements and expressions in TopLevelCodeDecls,
so the primary API for getting the top-level entities in source files
is based on getting declarations.

Start generalizing the representation by storing ASTNode instances at
the top level, rather than declaration pointers, updating many (but
not all!) uses of this API. The walk over declarations is a (cached)
filter to pick out all of the declarations. Existing parsed files are
unaffected (the parser still creates top-level code declarations), but
the new "macro expansion" source file kind skips creating top-level
code declarations so we get the pure parse tree. Additionally, some
generalized clients (like ASTScope lookup) will now look at the list
of items, so they'll be able to walk into statements and expressions
without the intervening TopLevelCodeDecl.

Over time, I'd like to phase out `getTopLevelDecls()` entirely,
relying on the new `getTopLevelItems()` for parsed content. We can
introduce TopLevelCodeDecls more lazily for semantic walks.
2022-11-01 08:04:15 -07:00
Doug Gregor
0cb2746c49 Keep track of source files created for macro expansions and such.
Introduce a new source file kind to describe source files for macro
expansions, and include the macro expression that they expand. This
establishes a "parent" relationship

Also track every kind of auxiliary source file---whether for macro
expansions or other reasons---that is introduced into a module, adding
an operation that allows us to find the source file that contains a
given source location.
2022-11-01 08:03:26 -07:00
Holly Borla
c4b946195e [AST] Replace the "type sequence" terminology with "parameter pack". 2022-10-10 16:28:13 -07:00
Nate Chandler
de19777da3 [AST] Retrieve @main type from module.
Added a convenience function to ModuleDecl to look up the entry point
@main type if there is one.
2022-09-23 15:26:22 -07:00
Alexis Laferrière
df85825592 [Sema|NFC] Rename enum cases to MissingImport
The concept of implicit import was already in use so let's differentiate
better the case of a missing import.
2022-09-19 15:13:57 -07:00
Slava Pestov
60e2fcb855 AST: ModuleDecl::lookupConformance() looks for conformances on Builtin.TheTupleType given a tuple type 2022-09-10 00:26:43 -04:00
Slava Pestov
70b553bcdc AST: Allow ModuleDecl::lookupConformance() to construct PackConformances for PackTypes 2022-09-10 00:26:43 -04:00
Alexis Laferrière
7b9d4e645c Merge pull request #61011 from xymus/spi-only-exportability
[Sema] Check exportability of @_spiOnly imported decls
2022-09-09 11:56:24 -07:00
Alexis Laferrière
6d396b4834 [Sema] Check @_spiOnly imported decls exportability
Decls imported via an @_spiOnly import can only be used in @_spi decls
signatures, internal decl signatures and non-inlinable function bodies.
2022-09-09 09:20:51 -07:00
QuietMisdreavus
f674b473ec introduce a @_documentation(...) attribute to influence SymbolGraphGen (#60242)
* add @_documentation(...) attribute to influence SymbolGraphGen

rdar://79049241
2022-09-06 14:12:42 -06:00
Alexis Laferrière
aaaef3411e [Sema] Intro @_spiOnly attribute and import filter
Introduce the attribute and basic import filter logic.
2022-09-01 15:16:44 -07:00
Alexis Laferrière
ae9bc59a93 Merge pull request #60659 from xymus/print-missing-imports
[ModuleInterface] Print missing imports in swiftinterface
2022-08-23 09:47:25 -07:00
Alexis Laferrière
66a994baa9 [Sema] Insert missing imports from any non-API modules
We can insert imports to any module from a source file that's part of a
non-API module without risking breaking the public swiftinterface.
2022-08-22 17:18:23 -07:00
Alexis Laferrière
9e3f5f9cea [ModuleInterface] Print missing imports in swiftinterface
Hack to fix swiftinterfaces in case of missing imports. We can get rid
of this logic when we don't leak the use of non-locally imported things
in API.
2022-08-19 12:32:43 -07:00
Allan Shortlidge
40eb1422bb IRGen/SIL: Fix IR linkage computation for inlined function references from modules imported @_weakLinked.
Include the parent `ModuleDecl` when serializing a `SILFunction` so that it is available on deserialized functions even though the full `DeclContext` is not present. With the parent module always available we can reliably compute whether the `SILFunction` comes from a module that was imported `@_weakLinked`.

Serialize the `DeclContext` member of `SILFunction` so that it can be used to look up the module that a function belongs to in order to compute weak import status.

Resolves rdar://98521248
2022-08-19 09:56:45 -07:00
Allan Shortlidge
1739528f6c Sema: Diagnose inconsistent use of @_weakLinked on import declarations. 2022-08-12 09:45:49 -07:00
Allan Shortlidge
7106c60e5a AST: Refactor HasImplementationOnlyImportsRequest to handle querying for imports with any ImportFlag. 2022-08-11 15:47:42 -07:00
Allan Shortlidge
f71a3232cf IRGen: Use extern_weak linkage for Clang symbols from @_weakLinked imported modules.
rdar://96098097
2022-08-11 11:02:57 -07:00
Allan Shortlidge
bc5f13cb6b AST: Accept @_weakLinked on import decls to force weak linkage of symbols from a module.
The effect of declaring an import `@_weakLinked` is to treat every declaration from the module as if it were declared with `@_weakLinked`. This is useful in environments where entire modules may not be present at runtime. Although it is already possible to instruct the linker to weakly link an entire dylib, a Swift attribute provides a way to declare intent in source code and also opens the door to diagnostics and other compiler behaviors that depend on knowing that all the module's symbols will be weakly linked.

rdar://96098097
2022-08-11 11:02:57 -07:00
Slava Pestov
63307760e4 AST: The underlying conformance of a specialized conformance is always a root conformance 2022-08-03 00:28:43 -04:00
Hamish Knight
9da53193da [AST] Remove ParameterTypeFlags from ParenType and TupleType
The last clients that relied on stashing parameter
type flags on these types are now gone.
2022-08-02 13:56:32 +01:00
Alexis Laferrière
35ff60530d Merge pull request #59955 from xymus/force-objc-import-publicly
[Sema] Force considering the `__ObjC` module as imported publicly
2022-07-08 09:16:55 -07:00
QuietMisdreavus
2d874788f6 [SymbolGraphGen] only include the given symbol for qualified imports (#59852)
* only include the given symbol for qualified imports

rdar://96309088

* re-exporting one type should not allow unrelated types to sneak in

* ensure that children of re-exported types are also re-exported
2022-07-08 09:13:08 -06:00