Commit Graph

1470 Commits

Author SHA1 Message Date
Alexis Laferrière
957639e27c Merge pull request #65631 from xymus/types-in-silfunction-mismatch
[SIL Serialization] Print mismatching SILFunction types on crash
2023-05-04 14:09:56 -07:00
Zoe Carver
f358cbea8e Merge pull request #65578 from zoecarver/disable-rvalue-ref
[cxx-interop] Disable rvalue references. We don't support them correc…
2023-05-04 10:15:56 -07:00
Alex Lorenz
62fd801828 [interop] C++ parameter of reference type should be imported as its pointee type in Swift even if parameter's type is type alias
This finally allows std::vector.push_back to be called with the pushed value directly passed into it
2023-05-03 18:23:03 -07:00
Alexis Laferrière
9bf0b6be05 [SIL Serialization] Print mismatching SILFunction types on error
The crash on `SILFunction type mismatch` provides little information and
tends to be difficult to reproduce. Let's print some of the available
information and distinguish the two failure sites.

I'm not confident all required information is written down so we may
need to improve this further in the future. This version still crashes
the compiler, we may want a proper type-check to prevent this failure
with a clean diagnostic for the example used here.

rdar://53821031
2023-05-03 17:24:55 -07:00
Allan Shortlidge
d1416ddd56 SILGen: Stub unavailable functions.
When `-unavailable-decl-optimization=stub` is specified, insert a call to
`_diagnoseUnavailableCodeReached()` at the beginning of the function to cause
it to trap if executed at run time.

Part of rdar://107388493
2023-05-03 15:19:31 -07:00
Alex Hoppen
237c70ea9c [CodeComplete] Offer completion suggestions for default argument values inside the macro declaration
We were not type checking the default argument initializer because `MacroDecl` is not an `AbstractFucntionDecl`. Add `MacroDecl` to the list of nodes we know how to get parameters from.

rdar://108163564
2023-05-01 13:48:18 -07:00
Anton Korobeynikov
0b235a7aac [AutoDiff[ Preserve substitutions maps while calculating derivative types (#65451)
The substituon map might contain proper specialization (e.g. t_0_0 -> Double) that is required to fully specify a derivate type (e.g. during reabstraction conversion from fully specified function type to a substituted one)

Fixes #65073
2023-04-26 23:11:15 -07:00
Slava Pestov
385a7beb45 SIL: Bridge 'any Sendable' via the id-as-Any path
Fixes rdar://problem/107264240.
2023-04-25 13:53:11 -04:00
Slava Pestov
66d601cc40 SILOptimizer: Teach CSE about scalar_pack_index, dynamic_pack_index, tuple_pack_element_addr 2023-04-12 17:33:31 -04:00
Erik Eckstein
c4ae7fe9e6 move-only: support deinits which get the self argument as indirect argument
This happens for address-only move-only types.
2023-04-11 10:25:49 +02:00
Erik Eckstein
7d70a70acf SIL: add the drop_deinit instruction
his instruction is a marker for a following destroy instruction to suppress the call of the move-only type's deinitializer.
2023-04-11 10:25:48 +02:00
Ravi Kandhadai
1b6d160c5c Merge pull request #65003 from ravikandhadai/main
[Constant Evaluator] Enable SILConstants::setIndexedElement function to work with aggregates containing unknown values
2023-04-07 17:27:11 -07:00
Ravi Kandhadai
e02d27c7d2 [Constant Evaluator] Enable SILConstants::setIndexedElement function
to work with aggregates containing unknown values. Such aggregates
can be generated when an instruction is skipped during constant
evaluation and its results are used to create a struct.
2023-04-06 21:41:39 -07:00
Nate Chandler
6e7a91b92d [TypeLowering] Fixed verifier variable shadowing.
To work around a build failure on MSVC,
f53e88b25b changed what was stored in the
verifier’s worklist from a `TaggedEnum<ValueDecl *, unsigned>` to two
fields `ValueDecl *` and `Optional<unsigned>` with the idea that only
one should ever be non-none.  That change failed, however, to return the
_optional_ unsigned index represented by the value in the worklist,
instead returning the actual value.  That’s a problem because the
worklist can’t contain `Optional<unsigned>` but only unsigned with
`UINT_MAX` indicating "none".

rdar://107709069
2023-04-06 08:13:24 -07:00
John McCall
e355fd8c0e Merge pull request #64951 from rjmccall/pack-expansions-lowering-verifier
Fix the type-lowering verifier to handle pack expansions
2023-04-05 22:53:30 -04:00
John McCall
e609bdfb81 Walk into pack expansions in this verifier.
Fixes rdar://107664237
2023-04-05 16:58:49 -04:00
John McCall
c11cbfa6ce [NFC] Convert this code to use canonical types 2023-04-05 16:58:49 -04:00
Doug Gregor
0e2cce59a8 Make sure we visit auxiliary declarations for symbol visitation.
SIL symbol visitation wasn't visiting top-level auxiliary declarations,
which meant that it skipped peer and freestanding macros at module
scope. This would manifest in errors of the form

    <symbol> is in the generated IR file, but not in TBD file

Fixes rdar://107426276.
2023-04-05 11:45:41 -07:00
Adrian Prantl
829491b230 Merge pull request #64551 from adrian-prantl/88274783
Rebase SILScope generation on top of ASTScope
2023-04-05 08:30:13 -07:00
Adrian Prantl
158772c2ab Rebase SILScope generation on top of ASTScope.
This patch replaces the stateful generation of SILScope information in
SILGenFunction with data derived from the ASTScope hierarchy, which should be
100% in sync with the scopes needed for local variables. The goal is to
eliminate the surprising effects that the stack of cleanup operations can have
on the current state of SILBuilder leading to a fully deterministic (in the
sense of: predictible by a human) association of SILDebugScopes with
SILInstructions. The patch also eliminates the need to many workarounds. There
are still some accomodations for several Sema transformation passes such as
ResultBuilders, which don't correctly update the source locations when moving
around nodes. If these were implemented as macros, this problem would disappear.

This necessary rewrite of the macro scope handling included in this patch also
adds proper support nested macro expansions.

This fixes

rdar://88274783

and either fixes or at least partially addresses the following:

rdar://89252827
rdar://105186946
rdar://105757810
rdar://105997826
rdar://105102288
2023-04-04 15:20:11 -07:00
John McCall
9c9671b349 Merge pull request #64887 from rjmccall/vanishing-tuple-silgen
SILGen and SIL type lowering support for vanishing tuples
2023-04-04 12:41:29 -04:00
John McCall
ecd03584da Handle vanishing tuples correctly in type lowering.
Test to follow.
2023-04-03 23:16:09 -04:00
John McCall
30817b11dd Support vanishing tuples in the the general abstraction pattern routines. 2023-04-03 23:14:47 -04:00
Michael Gottesman
43d8ab24f4 [move-only] Add a new type of mark_must_check initable_but_not_consumable.
This is used to teach the checker that the thing being checked is supposed to be
uninitialized at the mark_must_check point so that we don't put a destroy_addr
there.

The way this is implemented is that we always initially add
assignable_but_not_consumable but in DI once we discover that the assign we are
guarding is an init, we convert the assignable to its initable variant.

rdar://106525988
2023-03-31 17:32:58 -07:00
nate-chandler
5e0267b9b7 Merge pull request #64553 from nate-chandler/eagermove_collections
[stdlib] Collection types are eagerMove.
2023-03-30 16:16:26 -07:00
Adrian Prantl
af3b73a8ac Merge pull request #64590 from adrian-prantl/implicit-sillocation
Preserve the Implicit attribute in SILLocation. (NFC)
2023-03-30 13:46:51 -07:00
Nate Chandler
ff3ec19878 [TypeLowering] Fix lexicality check for tuples.
Use the new mechanism for looking into tuples that properly handles
packs.
2023-03-30 11:04:47 -07:00
John McCall
03f4e5629e Merge pull request #64681 from rjmccall/more-variadic-fixes
More fixes for generating SIL for variadic generics
2023-03-28 19:25:31 -04:00
Allan Shortlidge
9a1a2c3b9d Merge pull request #64644 from tshortli/strip-unavailable-code
Introduce `-unavailable-decl-optimization`
2023-03-28 08:53:48 -07:00
nate-chandler
f009071d42 Merge pull request #64649 from nate-chandler/rdar107283101
[TypeLowering] NFC: Fix lexicality check for packs.
2023-03-28 07:03:39 -07:00
Konrad `ktoso` Malawski
0586c14b60 [Concurrency] SerialExecutor.isSameExclusiveExecutionContext (#64604) 2023-03-28 15:56:28 +09:00
John McCall
08a921198a Assert that we don't produce a SILFunction with a type with opened
type parameters.
2023-03-27 18:31:08 -04:00
John McCall
8421669a59 Pass down the substitutions of the original pattern when extracting
a subst abstraction pattern from a generic nominal type.
2023-03-27 18:31:08 -04:00
John McCall
280c91a54f Fix the dumping of AbstractionPatterns with substitutions 2023-03-27 18:31:08 -04:00
Nate Chandler
adb21a373a [TypeLowering] Fix lexicality check for packs.
In asserts builds, the lexicality of packs is verified via an
alternative code-path that walks into aggregates.  That walk needs to
proceed through packs.

rdar://107283101
2023-03-27 14:03:30 -07:00
Allan Shortlidge
ada0f09615 SILGen: Implement 'complete' unavailable decl optimization.
Avoid SIL lowering for declarations marked unavailable when
`-unavailable-decl-optimiation=complete` is specified.

Part of rdar://106674022
2023-03-27 11:40:54 -07:00
John McCall
c041d1061a Perform component-wise substitution of pack expansions immediately.
Substitution of a pack expansion type may now produce a pack type.
We immediately expand that pack when transforming a tuple, a function
parameter, or a pack.

I had to duplicate the component-wise transformation logic in the
simplifyType transform, which I'm not pleased about, but a little
code duplication seemed a lot better than trying to unify the code
in two very different places.

I think we're very close to being able to assert that pack expansion
shapes are either pack archetypes or pack parameters; unfortunately,
the pack matchers intentionally produce expansions of packs, and I
didn't want to add that to an already-large patch.
2023-03-26 04:12:59 -04:00
John McCall
3b3e53eb73 [NFC] Use InFlightSubstitution in the SIL type substituter 2023-03-25 18:54:14 -04:00
John McCall
06b5c97256 [NFC] Split the SIL type substitution code into its own file 2023-03-25 18:54:14 -04:00
Adrian Prantl
c5efebe784 Preserve the Implicit attribute in SILLocation. (NFC)
This change aims at reducing the need for SIL passes to check into the AST
storage of SILLocations. The end goal is to eventually merge this with the
autogenerated flag, but at the moment the emergent semantics of both properties
are not identical.
2023-03-23 14:59:05 -07:00
John McCall
debc8d9ebd [NFC] Move forEachTupleElement to use a generator 2023-03-22 22:04:36 -04:00
Adrian Prantl
63304d0787 SILLocation: Move pointsToEnd flag into ASTNodeTy. NFC
The pointsToEnd flag is only meaningful when combined with an AST node, and
moving it into the AST pointer frees up a bit in the flags bitfield for later
use.
2023-03-22 14:04:28 -07:00
John McCall
0c3c62bd73 [NFC] Rename isPackExpansion -> isOrigPackExpansion for clarity 2023-03-22 15:40:02 -04:00
John McCall
9fbecde9a0 Do proper parallel walks of orig+subst types when computing type
properties for struct and enum types.
2023-03-22 15:40:02 -04:00
John McCall
a0eeabc886 When computing the field type of a SILType, add substitutions to the orig type. 2023-03-22 15:40:02 -04:00
John McCall
8ff61d6a54 When we are performing SIL substitution, and we reach a type that
needs to be lowered, use an opaque abstraction pattern.

As I argue in the comment, we know that the orig type is now either
an opaque type or a type with high-level structure that is invariant
to lowering.  Substitution will not change the latter property, and
an opaque abstraction pattern is correct for the former.  Attempting
to create a "truer" abstraction pattern that preserves more structure
from the orig type is both pointless and problematic.  The
substitutions we just did may have replaced pack references with
non-pack types if there are active expansions in progress; this cannot
be easily explained in terms of substitutions.  (In theory, we could
pass a more opaque concept of substitutions through AbstractionPattern,
which might help with this.  That would also make it harder to catch
bugs with signature mismatches, though.)
2023-03-22 15:40:02 -04:00
John McCall
f99efc2f94 Fix unsafeGetSubstFieldType to propagate a substitution map in
whichever case it happens to be in.

This is a basic fix so that parallel walks on tuples and function
types in the substituted type will work .  Separately, though, I
do not think the places that use this really need to be passed an
orig type; this is used for computing type properties, and I am
not aware of any reason we should need an orig type to compute
type properties.  Additionally, the orig types computed by this
function are not really correct because of the substitution being
done in some cases, so it'd be very nice to rip this all out.
I'm not good to look into that right now, though.
2023-03-22 15:40:02 -04:00
John McCall
bbc682822a [NFC] Change the printing of AbstractionPattern to include the sub map 2023-03-22 15:40:02 -04:00
John McCall
7505a8a487 Merge pull request #64517 from rjmccall/arity-reabstraction-closures
Implement arity reabstraction for closures
2023-03-22 14:14:23 -04:00
John McCall
5cf05f501b Implement arity reabstraction for closures 2023-03-21 22:23:45 -04:00