Commit Graph

1575 Commits

Author SHA1 Message Date
Doug Gregor
c142205a50 Resolve an old compiler crasher via the new diagnostic formatter
The old diagnostic formatter would crash on some Fix-Its involving
Unicode characters. The new one does not.
2024-02-19 02:48:37 -10:00
Erik Eckstein
dccaa8f01f diagnose duplicated @_cdecl and @_silgen_name function names
Prints a regular error instead of crashing.
The check is done in SILGen, because it's simple. We could also do it earlier, but I don't see a strong reason for this.

rdar://75950093
2021-03-31 13:30:22 +02:00
Anthony Latsis
2133fe27df Sema: Have TypeResolution accept an unbound generic type opener function 2020-07-08 13:39:34 +03:00
Slava Pestov
31a78590a8 ASTMangler: Fix assertion when mangling invalid identifiers
We sometimes need to mangle invalid identifiers, for example when sorting
declarations in EmittedMembersRequest. Make sure this doesn't assert.
2020-06-29 22:17:56 -04:00
Doug Gregor
2f97d24969 Note a fixed compiler crasher 2020-06-04 23:19:47 -07:00
Slava Pestov
c543838854 Sema: Rewrite partial applications into closures
When a method is called with fewer than two parameter lists,
transform it into a fully-applied call by wrapping it in a
closure.

Eg,

Foo.bar => { self in { args... self.bar(args...) } }
foo.bar => { self in { args... self.bar(args...) } }(self)

super.bar => { args... in super.bar(args...) }

With this change, SILGen only ever sees fully-applied calls,
which will allow ripping out some code.

This new way of doing curry thunks fixes a long-standing bug
where unbound references to protocol methods did not work.

This is because such a reference must open the existential
*inside* the closure, after 'self' has been applied, whereas
the old SILGen implementation of curry thunks really wanted
the type of the method reference to match the opened type of
the method.

A follow-up cleanup will remove the SILGen curry thunk
implementation.

Fixes rdar://21289579 and https://bugs.swift.org/browse/SR-75.
2020-03-18 09:29:22 -04:00
Luciano Almeida
7557f29a27 Reverting file location 2019-06-26 17:49:47 -03:00
Luciano Almeida
6331e9a1cd Reverting file location 2019-06-26 17:49:23 -03:00
Luciano Almeida
2ef18488d6 Walking through the expr to set the types and type variables in the constraint system before add convertion constraint 2019-05-27 22:57:56 -03:00
Alexis Laferrière
bddb40dacf GSB: ignore generic types in expandConformanceRequirement
Fixes crashes in 28437-swift-typechecker-validatedecl.swift (from previous commit)
and the compiler crasher 28861-gpdecl-getdepth-generictypeparamdecl-
invaliddepth-parameter-hasnt-been-validated.swift.
2019-04-30 10:43:23 -07:00
Saleem Abdulrasool
149f6b6b81 test: disable test for incorrect behaviour
This test is testing that the verifier aborts on invalid input.
SR-10459
2019-04-11 18:54:02 -07:00
Stephen Canon
28962b5754 Move most of the simd operators into an optional module (#20914)
* Move most of the simd operators into an optional module

Adding simd to the stdlib caused some typechecker regressions. We can resolve them in the near-term by making the types universally available, but moving the arithmetic operators into a separate module that must be explicitly imported.

* Move two fuzzing tests back to fixed.

* Add SIMDOperators as a dependency for MediaPlayer.

* Move the .-prefixed operator declarations back into the stdlib.
2018-11-30 16:30:15 -05:00
Stephen Canon
fb8b9e143d SIMD into stdlib
Implements SE-0229.

Also updates simd module types in the Apple SDKs to use the new types, and updates a couple tests to work with the new types and protocols.
2018-11-29 17:09:01 -05:00
Doug Gregor
de18384d89 [AST] Don’t deserialize members of @objc protocol looking for associated types
Thanks to @slavapestov for pointing this out! The optimization to avoid
looking through the members of a protocol that can’t possibly have any
associated types was for both deserialized protocols and imported
protocols, but I only supported the former in my previous change. Check
both cases and make the reasons much more obvious.

Also, that change resolved an existing compiler crasher as well.
2018-10-06 22:08:45 -07:00
Huon Wilson
ea1560f43b [AST] Member lookup in the GSB needs to understand equivalence classes with concrete types.
A constraint like `Parameter == SomethingConcrete` means references to
`Parameter` in that context behave like `SomethingConcrete`, including for name
resolution. Handling the parameter as just a parameter type means that it won't
find any non-protocol nested types (i.e. things other than associated types and
protocol typealiases are invisible).

Fixes rdar://problem/42136457 and SR-8240.
2018-07-17 22:54:22 +10:00
Slava Pestov
d4782b0fab Sema: Another validateDeclForNameLookup() state transition bug 2018-07-10 17:01:12 -07:00
Slava Pestov
8cd89bd709 Sema: Fix archetype vs interface type mixup with type in generic function 2018-07-10 17:01:12 -07:00
Slava Pestov
00b3ce18ca AST: Fix crash when doing name lookup into class with circular inheritance 2018-07-10 17:01:12 -07:00
Slava Pestov
559c0fd33d AST: Remove assertion in typo correction
CSDiag can try doing lookups on unbound generic types, so just remove this
assertion.
2018-07-10 17:01:12 -07:00
Slava Pestov
4878889c1e Sema: Better fix for <rdar://problem/36449760> 2018-07-10 17:01:12 -07:00
Slava Pestov
3ae11e6536 Sema: Fix a recusive validation crasher 2018-07-10 17:01:12 -07:00
Slava Pestov
ef864094b8 Sema: Fix crash when accessing nominal member of protocol 2018-07-10 17:01:12 -07:00
Slava Pestov
4fa4133134 Sema: Fix crash with UnresolvedType in coerceExistential()
Fixes <rdar://problem/34357545>.
2018-07-10 17:01:12 -07:00
Slava Pestov
381483bd74 AST: Remove Expr's LValueAccessKind 2018-07-05 23:54:13 -07:00
Doug Gregor
f4359b73f9 Merge pull request #17729 from DougGregor/minimize-override-checking
[Type checker] Minimize checking needed to compute the set of overridden declarations
2018-07-05 06:38:46 -07:00
Doug Gregor
7279eeeeac [Type checker] Perform more minimal checking in resolveOverriddenDecl().
Rather than deferring to the heavyweight validateDeclForNameLookup()
to perform the “get overridden decls” operation, perform a much more
minimal validation that only looks for exact matches when the ‘override’
modifier is present.

The more-extensive checking (e.g., that one didn’t forget an override
modifier) is only performed as part of the “full” type checking of
a declaration, which will typically only be done within the same source
file as the declaration. The intent here is to reduce the amount of
work performed to check overrides cross-file, and limit the dependencies
of the “get overridden decls” operation.
2018-07-03 17:26:38 -07:00
Slava Pestov
80232e8c49 Resolve a disabled compiler crasher fixed by my recent inheritance clause changes
Fixes <rdar://problem/38932729>.
2018-07-03 15:42:31 -07:00
John McCall
9bee3cac5a Generalize storage implementations to support generalized accessors.
The storage kind has been replaced with three separate "impl kinds",
one for each of the basic access kinds (read, write, and read/write).
This makes it far easier to mix-and-match implementations of different
accessors, as well as subtleties like implementing both a setter
and an independent read/write operation.

AccessStrategy has become a bit more explicit about how exactly the
access should be implemented.  For example, the accessor-based kinds
now carry the exact accessor intended to be used.  Also, I've shifted
responsibilities slightly between AccessStrategy and AccessSemantics
so that AccessSemantics::Ordinary can be used except in the sorts of
semantic-bypasses that accessor synthesis wants.  This requires
knowing the correct DC of the access when computing the access strategy;
the upshot is that SILGenFunction now needs a DC.

Accessor synthesis has been reworked so that only the declarations are
built immediately; body synthesis can be safely delayed out of the main
decl-checking path.  This caused a large number of ramifications,
especially for lazy properties, and greatly inflated the size of this
patch.  That is... really regrettable.  The impetus for changing this
was necessity: I needed to rework accessor synthesis to end its reliance
on distinctions like Stored vs. StoredWithTrivialAccessors, and those
fixes were exposing serious re-entrancy problems, and fixing that... well.
Breaking the fixes apart at this point would be a serious endeavor.
2018-06-30 05:19:03 -04:00
Doug Gregor
ac9b3cb936 Update a few recently-resolved crashers. 2018-06-16 08:41:00 -06:00
Doug Gregor
ebd774bcd1 [Sema] Eliminate the last use of the IterativeTypeChecker.
Implement TypeChecker::resolveInheritedProtocols() in terms of
"getInheritedType()" queries, instead.

[Sema] Put back resolveInheritedProtocols().

We're still depending on it to update state in some cases.
2018-06-14 15:29:57 -07:00
Doug Gregor
2b2e143f59 [Request-Evaluator] Introduce a request for getting an "inherited type". 2018-06-14 15:29:57 -07:00
Pavel Yaskevich
11ba7e0f42 [CSSimplify] When trying to simplify bind with error type fail gracefully
Since member lookup doesn't check requirements
it might sometimes return types which are not
visible in the current context e.g. typealias
defined in constrained extension, substitution
of which might produce error type for base, so
assignement should thead lightly and just fail
if it encounters such types.

Resolves: rdar://problem/39931339
Resolves: SR-5013
2018-05-28 00:24:54 -07:00
Doug Gregor
539c352353 [GenericSignatureBuilder] Block recursion through getTypeInContext().
We could end up recursing through getTypeInContext() before we had time to
diagnose the recursion, so be *certain* that we can't recurse here to fix
a few crashes.
2018-05-03 18:11:35 -07:00
Pavel Yaskevich
01312d9623 Merge pull request #16276 from xedin/add-implicit-inits-with-getparams
[Sema] Refactor member type matching from `checkOverrides` to make it reusable
2018-05-03 00:16:24 -07:00
Pavel Yaskevich
394ac6f4f1 [AST] lookupSubstition should produce nothing if there are not substitutions
If `SubstitutionMap` is empty there is nothing to replace so
we should always return empty substitution type and/or conformance ref.
2018-05-02 15:11:25 -07:00
Doug Gregor
bc5bbe8b64 [AST] Use SubstitutionMap, not SubstitutionList, in SILBoxType.
Eliminate the last place in the AST proper that stores
SubstitutionLists rather than SubstitutionMaps. Randomly fixes a
crasher, too.
2018-05-02 13:39:21 -07:00
Robert Widmann
9973b31d5b Skip invalid declarations in SourceLookupCache
Crashers 28598 and 28778 are creating invalid validation requests for the ITC
by using unqualified lookup to get the validator to jump inside of a
transitively invalid DeclContext.

Just don't load these members.
2018-04-16 13:10:34 +02:00
Pavel Yaskevich
3ba6ad654b [TypeChecker] Fix lookup of the dependent type through typealias
While trying to resolve nested type component with type parameter
as a parent, try to resolve it as dependent member directly but
if that fails go through longer resolution path which is required
in case member type is accessed using `typealias`.

Resolves: rdar://problem/39253925
2018-04-09 16:01:37 -07:00
David Zarzycki
67710606e6 [Parse] Move tok::amp_prefix closer to parameter list logic
The amp_prefix token is currently tolerated in any unary expression
context and then diagnosed later by Sema. This patch changes parsing to
only accept tok::amp_prefix in its allowed position: parameter lists.

This also fixes two "compiler crasher" tests.
2018-03-30 17:56:36 -04:00
Mark Lacey
784df65753 Disable a test that seems to infinitely recurse on a diagnostic sometimes.
Once the associated bug is fixed we can re-enable.
2018-03-27 16:31:16 -07:00
Doug Gregor
325fdd2f12 [AST] Don’t propagate all recursive properties to BoundNameAliasType.
With the exception of “has type variable”, which affects the arena used
for storage of a BoundNameAliasType, only propagate recursive properties
from the underlying type to a BoundNameAliasType, because the other
properties (e.g., “has archetype” or “has type parameter”) pulled from
syntactic sugar don’t apply.
2018-03-25 20:46:07 -07:00
Doug Gregor
3dfd7377ef Merge pull request #15416 from DougGregor/generic-typealias-sugar
[AST] Preserve type sugar for generic typealiases
2018-03-22 13:15:46 -07:00
Slava Pestov
a6ff28285c Sema: Move most of DeclChecker::visitFuncDecl() to validateDecl() 2018-03-21 23:54:48 -07:00
Doug Gregor
e6c91b3985 Start using BoundNameAliasType for non-generic typealiases in generic contexts
Currently, when we reference a (non-generic) typealias within a
generic context, we would completely lose type sugar for the
typealias, replacing it with the underlying type. Instead, use
BoundNameAliasType for this purpose, which allows us to maintain all
of the type sugar as well as storing complete substitutions for later
use.
2018-03-21 23:49:33 -07:00
Slava Pestov
f9f5ebbba9 Sema: Remove DeclChecker::IsSecondPass
The DeclChecker had three possible states:

- IsFirstPass true, IsSecondPass false. This is the 'first pass' for
  declarations that appear at the top-level, or are nested inside
  top-level types.

- IsFirstPass false, IsSecondPass true. This is the 'second pass' for
  declarations that appear at the top-level, or are nested inside
  top-level types.

- IsFirstPass false, IsSecondPass false. This was used for (some)
  local declarations.

This is unnecessarily confusing. We can eliminate the third state
by calling typeCheckDecl() twice in a few places. This allows
IsSecondPass to be removed entirely since it's now always equal to
!IsFirstPass.
2018-03-21 21:41:38 -07:00
Pavel Yaskevich
8c17b925e6 [ConstraintSystem] Add TypeLoc caching to constraint system
This is useful for explicit casts and type expressions, where
type loc and expression types might be different, and allows
constraint solver to avoid setting opened types to expressions
which resolves multiple crashes.
2018-02-13 00:08:56 -08:00
Pavel Yaskevich
c6ff7b40cc [CSBindings] Look through optional types when trying to validate l-valueness of the new bindings
When bindings are picked for particular type variable, right-hand
side of the binding might be another type variable wrapped into optional
type, when trying to determine if both sides of the binding have the
same l-valueness it's imperative to look throught optional type of the
right-hand side. Otherwise new binding might be effectively unsolvable.

Resolves: rdar://problem/37291371
2018-02-08 01:55:39 -08:00
Huon Wilson
9aed3e83a8 [GSB] Infer requirements from parents of types.
A type Foo<...>.Bar may only exist conditionally (i.e. constraints on the
generic parameters of Foo), in which case those conditional requirements
should be implied when Foo<...>.Bar is mentioned.

Fixes SR-6850.
2018-02-02 08:44:30 +11:00
Doug Gregor
24aa030f0c [Associated type inference] Break recursive inference and fail predictably.
There was a path through associated type inference where we would end
up recording a type witness that contained an error, but for which we
had not reported that error, which would lead to downstream
crashes. Make sure that we reject such inferences.

And because it triggers once we fix this issue... make sure break
recursion when trying to resolve type witnesses lazily.

Fixes the crash in SR-6609 / rdar://problem/36038033, but we're still
failing to infer in those cases.
2018-01-24 15:58:26 -08:00
Doug Gregor
b11d5447c6 Merge pull request #13643 from DougGregor/redecl-fewer-validations
[Type checker] Make redeclaration checking validate fewer declarations.
2017-12-31 20:20:53 -08:00