Commit Graph

1018 Commits

Author SHA1 Message Date
Doug Gregor
200f2340d9 [Macros] Be deliberate about walking macro arguments vs. expansions
Provide ASTWalker with a customization point to specify whether to
check macro arguments (which are type checked but never emitted), the
macro expansion (which is the result of applying the macro and is
actually emitted into the source), or both. Provide answers for the
~115 different ASTWalker visitors throughout the code base.

Fixes rdar://104042945, which concerns checking of effects in
macro arguments---which we shouldn't do.
2023-02-28 17:48:23 -08:00
Joe Groff
1311df6544 AST: Combine various ownership TypeReprs into one OwnershipTypeRepr.
This lets us consolidate code paths that mostly run in parallel over the
existing InOutTypeRepr/SharedTypeRepr/OwnedTypeRepr family of types. This
patch by itself is NFC but makes it easier to introduce new spellings,
particularly the newly-official `borrowing` and `consuming` modifiers
that were approved in SE-0377.
2023-02-28 09:15:43 -08:00
Holly Borla
f6c3aaab96 [Macros] Return a ConcreteDeclRef from ResolveMacroRequest.
This allows callers to access inferred generic arguments for macro
expansion invocations.
2023-02-20 21:17:19 -08:00
Slava Pestov
7d1f7f62e6 Merge pull request #63704 from slavapestov/pack-element-type-repr-fixes
A couple of PackElementTypeRepr fixes
2023-02-16 07:51:29 -05:00
Slava Pestov
e0c341d0ac AST: Rename PackReferenceTypeRepr => PackElementTypeRepr 2023-02-15 22:37:07 -05:00
Holly Borla
c33c925e81 [Macros] Remove the macro role argument to ResolveMacroRequest.
The macro role argument presented an opportunity for callers to accidentally
invoke this request twice for the same macro with slightly different macro
roles passed in, which resulted in re-typechecking the macro arguments.
Instead, derive the corresponding macro roles from the macro reference syntax.
2023-02-14 22:38:53 -08:00
Angela Laar
0eb072c1d1 Merge pull request #63542 from angela-laar/fix-type-alias-implicit-some
[NameLookup] Type Aliases should resolve as opaque
2023-02-13 10:48:50 -08:00
Doug Gregor
7ebc86e584 Have attached macro requests return an array of expansion buffer IDs.
The result values of the expansion requests for attached macros tended
to be useless, because most of their operation is via side effects on
the nodes they are attached to. Replace the result values with an
array of expansion buffer IDs, so clients can see what effect the
macro expansion had.
2023-02-11 11:21:43 -08:00
Angela Laar
26c62b1635 [NameLookup] Type Aliases should resolve as opaque
Type aliases for plain protocols should resolve as
opaque types with implicit some feature flag

Fixes rdar://101403690
2023-02-10 09:40:54 -08:00
Richard Wei
01e4c8df26 [Macros] Use name lookup for lazy declaration macro expansion (#63411)
- Use the name lookup table instead of adding members from a macro expansion to the parent decl context.
- Require declaration macros to specify introduced names and used the declared names to guide macro expansions lazily.
2023-02-07 11:24:42 +08:00
Holly Borla
5c3872748a [Macros] Invoke member macro expansion during qualified lookup.
Otherwise, members that are added via macro expansion will not be visible
in other source files.
2023-02-05 21:23:30 -08:00
Angela Laar
5a91cea689 [Namelookup] Wallk into GenericIdentTypeRepr 2023-02-03 14:40:50 -08:00
Angela Laar
c837baa313 [Sema] Diagnose DisallowedExistential in type resolution 2023-02-03 14:40:50 -08:00
Angela Laar
acc90b1b79 [NameLookup] Opaque Type Collector should skip existential types 2023-02-03 14:40:50 -08:00
Hamish Knight
a40f1abaff Introduce if/switch expressions
Introduce SingleValueStmtExpr, which allows the
embedding of a statement in an expression context.
This then allows us to parse and type-check `if`
and `switch` statements as expressions, gated
behind the `IfSwitchExpression` experimental
feature for now. In the future,
SingleValueStmtExpr could also be used for e.g
`do` expressions.

For now, only single expression branches are
supported for producing a value from an
`if`/`switch` expression, and each branch is
type-checked independently. A multi-statement
branch may only appear if it ends with a `throw`,
and it may not `break`, `continue`, or `return`.

The placement of `if`/`switch` expressions is also
currently limited by a syntactic use diagnostic.
Currently they're only allowed in bindings,
assignments, throws, and returns. But this could
be lifted in the future if desired.
2023-02-01 15:30:18 +00:00
Holly Borla
3e6fdb8807 [NameLookup] The custom attribute lookup request only returns nominal types.
Macro attribute lookup is now implemented in ResolveMacroRequest, which happens
later because it needs overload resolution to resolve a custom attribute to a
macro decl.
2023-01-26 17:10:28 -08:00
Holly Borla
09287a1bd6 [Macros] Separate determining whether a custom attribute is a macro and
type checking macro attribute arguments into two different requests.
2023-01-22 16:49:30 -08:00
Holly Borla
8221409931 [Macros] Distinguish between attributes that do not reference macros and
invalid macro attributes in `findMacroForCustomAttr`.
2023-01-22 12:45:18 -08:00
Holly Borla
0ca5b8a1f9 [NFC] Move findMacroForCustomAttr to TypeCheckMacros.cpp. 2023-01-21 12:23:34 -08:00
Doug Gregor
de16b47875 [Macros] Introduce the @attached attribute for declaring attached macros.
Describe attached macros with the `@attached` attribute, providing the
macro role and affected names as arguments to the macro. The form of
this macro will remain the same as it gains other kinds of attached
macro roles beyond "accessor".

Remove the "accessors" role from `@declaration`, which will be going
away.
2023-01-13 22:47:59 -08:00
Doug Gregor
0b8c335a97 [Macros] Allow custom attributes to resolve to attached macro declarations.
Introduce appropriate name lookup for custom attributes to find macros
at module scope, and prefer those to types of the same name. We don't
do anything with the macros we found other than ignore them, for the
moment.
2023-01-11 23:12:56 -08:00
Doug Gregor
69649a40a6 Generalize CustomAttrNominalRequest's name and signature to account for macros 2023-01-11 21:28:26 -08:00
John McCall
2afb336d79 Parse Pack{...} types in SIL mode
This is needed for general fidelity in SIL, since generic argument
lists are used for a lot of different things that aren't restricted
from containing multiple packs.  I haven't actually done the work to
use Pack structure to disambiguate the resolution of pack parameters,
but this is a good start.

We'll probably need something like this in source eventually, so
there's no reason to regret adding all the infrastructure for it.
2023-01-11 03:11:30 -05:00
Richard Wei
f17b7c48bf [Macros] Freestanding declaration macros
Add support for freestanding declaration macros.

- Parse `@declaration` attribute.
- Type check and expand `MacroExpansionDecl`.

Known issues:
- Generic macros are not yet handled.
- Expansion does not work when the parent decl context is `BraceStmt`. Need to parse freestanding declaration macro expansions in `BraceStmt` as `MacroExpansionDecl`, and add expanded decls to name lookup.
2023-01-10 19:09:11 -08:00
Holly Borla
74bf2f3e7a [AST] Introduce a syntactic distinction betweek vararg type reprs and
pack expansion type reprs.

Classic variadic parameters still use the postfix ellipsis syntax, and
pack expansion types now use a prefix 'repeat' keyword.
2023-01-07 09:50:11 -08:00
Anthony Latsis
1bb407ac8c [NFC] AST: Rename ComponentIdentTypeReprIdentTypeRepr 2023-01-07 07:15:36 +03:00
Anthony Latsis
ad5d55c36e [NFC] AST: Rename IdentTypeReprDeclRefTypeRepr 2023-01-07 07:14:44 +03:00
Anthony Latsis
746c7aff7d [NFC] AST: Rename CompoundIdentTypeReprMemberTypeRepr 2023-01-07 07:14:41 +03:00
Anthony Latsis
0c3a72d4d7 [NFC] CompoundIdentTypeRepr: Supplant getComponents with getBaseComponent & getMemberComponents
Also store the base component separately as an arbitrary `TypeRepr`.
2023-01-07 07:11:30 +03:00
Anthony Latsis
7be645e2de [NFC] Remove some uses of CompoundIdentTypeRepr::getComponents 2023-01-07 07:11:30 +03:00
Anthony Latsis
2113e175f5 [NFC] AST: Remove IdentTypeRepr::ComponentRange 2023-01-07 07:11:30 +03:00
Anthony Latsis
8935acdd5b [NFC] AST: Remove IdentTypeRepr::create 2023-01-07 07:11:29 +03:00
Rintaro Ishizaki
4e334498e8 [CodeCompletion] Don't suggest opaque generic parameter types
'some' parameter types don't have spelling.

rdar://102958462
2022-12-15 13:26:17 -08:00
Holly Borla
41298c2466 [AST] Introduce PackReferenceTypeRepr for pack references spelled with
a contextual 'each' keyword.
2022-12-10 16:16:04 -08:00
Slava Pestov
2875cac27f AST: Clean up prepareLookupTable() a bit more 2022-11-28 23:57:53 -05:00
Slava Pestov
cc3a53091d AST: Remove MemberLookupTable::updateLookupTable() 2022-11-28 23:57:53 -05:00
Slava Pestov
3113c62a2d AST: Fix performance regression in lookupDirect()
Every call to lookupDirect() was calling prepareLookupTable() followed
by addLoadedExtensions(). While prepareLookupTable() only did its work
once, addLoadedExtensions() would walk all currently-loaded members of
all extensions every time.

However, just merging it with prepareLookupTable() was not enough,
because other places call prepareLookupTable(), which ends up loading
extensions too early after this change.

Instead, separate out the lazy allocation of the lookup table from
initialization. getLookupTable() returns a potentially-uninitialized
lookup table, and prepareLookupTable() now does what it did before
as well as what was formerly in addLoadedExtensions().

With this new split, getLookupTable() can be used instead of
prepareLookupTable() to avoid request cycles in a couple of places.
2022-11-28 23:57:53 -05:00
Pavel Yaskevich
0aa036a495 Merge pull request #61915 from xedin/switch-protocol-checking-to-abi-members
[AST/Sema] Switch protocol requirement inference to use `getABIMembers()`
2022-11-04 16:21:01 -07:00
Pavel Yaskevich
82f34b90c1 [AST] NameLookup: Add a request to gather protocol requirements 2022-11-04 11:11:41 -07:00
Robert Widmann
7944635f2e Merge pull request #61898 from CodaFi/i-write-syns-not-tragedies 2022-11-04 08:20:47 -07:00
Robert Widmann
2d07f382c5 Delete _InternalSwiftSyntaxParser And Its Build Infrastructure
This is the start of the removal of the C++ implementation of libSyntax
in favor of the new Swift Parser and Swift Syntax libraries. Now that
the Swift Parser has switched the SwiftSyntaxParser library over to
being a thin wrapper around the Swift Parser, there is no longer any
reason we need to retain any libSyntax infrastructure in the swift
compiler.

As a first step, delete the infrastructure that builds
lib_InternalSwiftSyntaxParser and convert any scripts that mention
it to instead mention the static mirror libraries. The --swiftsyntax
build-script flag has been retained and will now just execute the
SwiftSyntax and Swift Parser builds with the just-built tools.
2022-11-02 10:35:29 -07:00
Slava Pestov
0e4ccb21ed AST: Remove various references to AbstractTypeParamDecl 2022-11-01 19:13:46 -04:00
Becca Royal-Gordon
3e4ea43adf Don’t diagnose @_objcImpl conflicts with inherited inits
Previously, Swift would reject an `override public init(…)` in an `@_objcImplementation` because ClangImporter would have already synthesized inherited initializers that conflicted with the overrides. Ignore these spurious conflicts, and also move a check out of IsObjCRequest and into the conflict-handling code.

Additional work towards rdar://70730077.
2022-10-27 17:00:43 -07:00
Hamish Knight
b645e63ce5 [AST] NFC: Refactor GenericTypeParamDecl construction
Add distinct overloads for the parser,
deserialization and code synthesis.
2022-10-14 15:40:12 +01:00
Holly Borla
c4b946195e [AST] Replace the "type sequence" terminology with "parameter pack". 2022-10-10 16:28:13 -07:00
Luciano Almeida
a95f60e387 [AST] Refactor generic parameter list parse logic for AccessorDecl 2022-10-07 09:43:08 -03:00
Luciano Almeida
14c01144b2 [AST] Consider storage signature when computing opaque params implicit generic params 2022-10-03 22:48:22 -03:00
Pavel Yaskevich
1a79d93121 Merge pull request #40702 from calda/cal--implicit-weak-self
[SE-0365] Allow implicit self for `weak self` captures
2022-09-30 10:30:57 -07:00
Cal Stephens
5946c66962 Style updates 2022-09-23 07:09:52 -07:00
Cal Stephens
9dd56f9daf Move remaining logic in LookupResultEntry::getBaseDecl() to ASTScope::lookupUnqualified impl, add more extensive tests, fix failing tests 2022-09-22 11:04:08 -07:00