Commit Graph

67 Commits

Author SHA1 Message Date
Alex Hoppen
66104395d7 [Sema/SourceKit] Emit same diagnostics for missing protocol requirements on the command line and in SourceKit
Some editors use diagnostics from SourceKit to replace build issues. This causes issues if the diagnostics from SourceKit are formatted differently than the build issues. Make sure they are rendered the same way, removing most uses of `DiagnosticsEditorMode`.

To do so, always emit the `add stubs for conformance` note (which previously was only emitted in editor mode) and remove all `; add <something>` suffixes from notes that state which requirements are missing.

rdar://129283608
2024-08-07 14:01:30 -07:00
Becca Royal-Gordon
3732c75e97 Adopt %kind for certain access control diagnostics
These particular changes slightly alter some diagnostics.
2023-07-19 13:06:51 -07:00
Anthony Latsis
1feed1dff0 Gardening: Migrate test suite to GH issues (file names): multifile 2022-09-18 19:07:45 +03:00
Alastair Houghton
c995942000 Add a test for redundant protocol conformance.
Added a test that builds two dynamic libraries and sets up a redundant protocol
conformance (we use dynamic libraries because the compiler will normally reject
redundant conformances), then checks that when we rely on it, we get a warning
message.
2021-06-18 10:06:20 +01:00
Robert Widmann
eba9bbe36b Use the Formal Access *Scope* of the Extended Nominal For Its Max Access
Formal access alone does not take into account @testable imports of
internal types. This prevented otherwise valid conditional conformances
of these types from compiling.

rdar://72875683
2021-01-15 17:10:49 -08:00
Doug Gregor
0d568a93d4 [SE-0289] Update diagnostics & many other strings to "result builders" 2020-10-20 21:44:09 -07:00
Doug Gregor
6a40a3a8aa [SE-0289] Add support for @resultBuilder.
"Function builders" are being renamed to "result builders". Add the
corresponding `@resultBuilder` attribute, with `@_functionBuilder` as
an alias for it, Update test cases to use @resultBuilder.
2020-10-20 13:24:51 -07:00
Slava Pestov
ab83d907ac Sema: Fix cycle between closure type computation and EmittedMembersRequest
EmittedMembersRequest needs a stable order for synthesized members
to ensure that vtable layout is computed consistently across frontend
jobs. This used to use the mangled name as the sort key.

However, the mangling includes the type of all outer contexts, and if
an outer type is a closure, we would need to compute the type of the
closure. Computing the type of a closure might require type checking
its body though, which would in turn type check the local class, which
would invoke EmittedMembersRequest, introducing a cycle.

Instead, let's use the DeclName and string-ified type as the sort key.
This is simpler to compute than th mangled name, and breaks the cycle.

Fixes <rdar://problem/67842221>.
2020-09-01 18:30:25 -04:00
Varun Gandhi
a1716fe2a6 [Diagnostics] Update compiler diagnostics to use less jargon. (#31315)
Fixes rdar://problem/62375243.
2020-04-28 14:11:39 -07:00
Slava Pestov
8ee5d2931f Sema: Force property wrappers in EmittedMembersRequest::evaluate()
Fixes <rdar://problem/61229365>.
2020-04-09 19:57:12 -04:00
Slava Pestov
52c11c78d1 Sema: Property wrapper storage wrappers ($foo) inherit 'final' bit from original property
Otherwise, we would generate inconsistent vtable layouts for classes
with static properties that have attached wrappers. The reason is that
we normally force synthesis of the backing storage and storage wrapper
for each instance property wrapper as part of computing the lowered
stored properties.

However, there was no such forcing for static properties. But since a
static stored property (with an attached wrapper or otherwise) must be
'final', the real fix is to just ensure that the 'final' bit propagates
to the storage wrapper as well.

The backing storage property was already always final, so the issue
did not arise there.

Fixes <rdar://problem/59522703>, <https://bugs.swift.org/browse/SR-12429>.
2020-03-31 23:42:34 -04:00
Slava Pestov
4f93be1485 Add regression test for rdar://57265336
There was a logic error causing us to place nominal types on the
DeclsToFinalize list in the specific case where they were members
of an extension of a class.

Of course this kind of thing is indicative of bad design, and now,
the whole DeclsToFinalize list is gone. Let's add a regression
test for posterity.
2019-11-22 17:42:51 -05:00
Luciano Almeida
1184492d25 [Diagnostics] SR-11419 Diagnose protocol stub note in editor mode only (#28101)
* [TypeChecker] Enclosing stubs protocol note within editor mode

* [test] Removing note from test where there is no -diagnostics-editor-mode flag

* Formatting modified code

* [tests] Fixing tests under validation-tests
2019-11-06 07:42:48 -08:00
Doug Gregor
997fabbf16 [Type checker] Validate subscript declaration before using it.
Fixes SR-1148 / rdar://problem/55303660.
2019-09-24 07:21:42 -07:00
Slava Pestov
2be7573aa0 Sema: Remove synthesizeWitnessAccessorsForStorage()
We can lazily synthesize accessor witnesses from SILGen now.
2019-08-02 19:34:43 -04:00
Slava Pestov
42901546fb Sema: Add multi-file test case for @objc conformance checking
Make sure we test checkObjCWitnessSelector() in the multi-file
case.

I made some changes that regressed a source compatibility project
but the regression was not caught by our test suite, so make sure
we have a test for this now.
2019-08-02 19:34:43 -04:00
Slava Pestov
c12e004156 Sema: Fix multi-file edge case with accessor availability checking
When checking availability of referenced accessors, we may not have
synthesized the accessors yet. This meant that we didn't diagnose
references to internal(set) properties from inlinable contexts if
the property was defined in another file.
2019-08-02 19:34:43 -04:00
Slava Pestov
487258d919 SIL: Allow lowering ErrorType 2019-07-17 18:07:03 -04:00
Slava Pestov
7a4e7eda00 IRGen: Don't get enum element argument type until we need it
Instead of adding a resolveDeclSignature() call here, I'm going to live
dangerously and try to only get the enum element type in the case where
SIL type lowering has already computed it, that is, if the enum is not
indirect.

Soon this will become moot anyway because getInterfaceType() will be a
request.
2019-07-17 18:07:03 -04:00
swift-ci
7e5521cd89 Merge pull request #26071 from DougGregor/property-wrappers-final-rename 2019-07-10 16:34:57 -07:00
Doug Gregor
9a444242fb [SE-0258] Fixups for various renames of property wrappers. 2019-07-10 15:28:24 -07:00
Doug Gregor
1284878ad8 [SE-0258] Rename init(initialValue:) --> init(wrappedValue:).
Addresses core team decision on acceptance of property wrappers.

Fixes rdar://problem/48871069.
2019-07-10 14:26:53 -07:00
Xi Ge
1535bea268 FixCode: issue a separate note for protocol-stub fixit when the fixit location is in another file
Under non-editor mode, the fixit for inserting protocol stubs is associated with a note
pointing to the missing protocol member declaration which could stay in a separate file from
the conforming type, leading to the behavior of rdar://51534405. This change checks if
the fixit is in a separate file and issues another note to carry the fixit if so.

rdar://51534405
2019-07-10 12:30:54 -07:00
Slava Pestov
ebba615338 Add regression test for SR-11018
https://bugs.swift.org/browse/SR-11018 / rdar://problem/52194213
2019-07-06 13:36:22 -04:00
swift-ci
565f1b363a Merge pull request #25816 from DougGregor/property-wrappers-multifile-rdar51725203 2019-06-27 01:13:47 -07:00
Doug Gregor
ef17b38106 [SE-0258] Trigger synthesis of _foo/$foo from name lookup.
Fix a bug with cross-file uses of the synthesized _foo/$foo for
properties with attached wrappers by implicitly triggering the
appropriate synthesis during name lookup.

Fixes rdar://problem/51725203.
2019-06-27 00:08:31 -07:00
Arnold Schwaighofer
6f4c5c48ce IRGen: Correctly compute fixed sized'ness of resilient enums
rdar://51422528
2019-06-25 11:57:56 -07:00
Doug Gregor
592887cb53 [Type checker] Fix multi-file crasher for property wrapper backing storage.
Fixes rdar://problem/51810057
2019-06-24 22:35:51 -07:00
Slava Pestov
ce712dbf65 Sema: Bail out early from checkOverrideAccessControl() if we have protocol requirements 2019-06-13 17:27:56 -07:00
John McCall
007842261f Rework the requests for getting a parameter's function-builder type.
Turn the generic CustomAttrTypeRequest into a helper function and
introduce a FunctionBuilderTypeRequest that starts from a ParamDecl.
This has better caching characteristics and also means we only need to
do a single cache lookup in order to resolve the type in the normal path.
It also means we don't need as much parameterization in the cache.

In addition, check that the parameter has function type in the request,
not just when late-checking the attribute, and add a check that it isn't
an autoclosure.
2019-06-11 17:34:44 -07:00
Slava Pestov
5e39f0354e Sema: Fix crash-on-invalid with 'let' property in protocol
The protocol requirement storage declaration might not have accessors
created for it if it was incorrectly declared as a 'let' property
inside the protocol.

There might be other cases where we had failed to synthesize the
requirement's accessors, and crash here; this should hopefully make
all of those more robust.

Fixes <rdar://problem/48994271>.
2019-05-30 16:43:43 -04:00
Saleem Abdulrasool
d16689278c multifile: make protocol-conformance-member pass on Windows
PE/COFF does not include a symbol table in the generated executable
binary.  Instead, use `public` to expose the getter, and then use
`-coff-exports` from `llvm-readobj` to get the symbols that are
exported.  Fortunately, the same tool can be used to list the symbol
table contents for ELF and MachO binary.  This allows us to share the
test across all the targets.
2019-03-26 10:46:44 -07:00
Slava Pestov
a6f6dc01bc Sema: Fix order dependency between lazy getter body synthesis and capture computation
If we computed captures before completing a lazy getter body, we would fail to
consider the 'self' capture properly. Instead make it resilient to such ordering
issues by checking in capture computation if the lazy property has a getter yet
or not.
2018-12-07 17:10:15 -05:00
John McCall
b9f4b17a33 Mark lazy properties as having mutating getters immediately.
We were trying to do this when synthesizing the getter prototype, but
we don't do that immediately when we're just type-checking a reference
to the storage, which could lead to the reference thinking that the
getter was non-mutating.

Fixes rdar://45712204.
2018-11-26 17:36:13 -05:00
John McCall
05c951fdc9 Compute layout when emitting an other-constructor reference.
Fixes SE-9233, a crash due to a failure to validate a storage
declaration within a protocol when generating a call to an
initiializer.
2018-11-13 16:35:26 -05:00
Doug Gregor
1fc57ad667 [Test] Add test case for now-fixed rdar://problem/39805133 2018-10-10 21:53:20 -07:00
Davide Italiano
ef46ec08fc [AST] Update tests now that we preserve sugar. 2018-09-18 09:23:02 -07:00
Doug Gregor
8af269aca5 [Type checker] Make sure we have a generic signature when inheriting initializers.
Before adding implicit initializers synthesizes a new initializer, make sure that
we’ve validated the current class declaration to determine it’s generic signature.

Fixes rdar://problem/44235762.
2018-09-08 10:21:55 -07:00
Slava Pestov
a1ea56b20f Add test case for https://bugs.swift.org/browse/SR-8643 which is now fixed 2018-08-25 01:14:49 -07:00
Doug Gregor
e15f67e453 [Type checker] Marking a class as @objc doesn’t require an interface type.
Fixes the crash in SR-8540 / rdar://problem/43383512.
2018-08-20 10:05:13 -07:00
Doug Gregor
bb6272b194 [Type checker] Finalize witnesses when we finish checking a conformance.
This ensures that SILGen can build the witness table.
2018-08-18 10:44:12 -07:00
Doug Gregor
cb972072a6 [Type checker] Request nominal layout for all potential metadata sources.
Fixes the non-WMO crash in ReactiveCocoa (SR-8530), where IRGen was
attempting to fulfill a metadata request based on a nominal type whose
layout was not checked.
2018-08-17 15:03:02 -07:00
Doug Gregor
76eb767b97 [Type checker] Request nominal layout for the result types of function calls.
Once you’ve called a function and retrieved a result, IRGen will want
layout information for the result type. Make sure that the type checker
precomputes it.
2018-07-26 15:46:29 -07:00
Doug Gregor
c2bc23e734 [Type checker] Finalize referenced members of class extensions.
When we reference a member of a class extension, we need to
compute its overrides, @objc bit, and ‘dynamic’ status because SILGen
may rely on them. Do that consistently by adding such members to the
list of declarations to “finalize”.

Rework the finalization logic to handle the computation of each of those
bits, and never remove a finalized declaration from the set: rather,
process new declarations as they enter the set, to avoid looping or
extra state bits.

Fixes rdar://problem/42440686.
2018-07-24 16:51:25 -07:00
Doug Gregor
9939834a76 [Type checker] Validate potentially-overridden decls when needed.
When computing the type of a potentially-overriden declaration, make sure
we have an interface type. Add a test to ensure that we validate
overrides cross-file correctly.
2018-07-04 22:45:10 -07:00
Arnold Schwaighofer
9048e97e83 Executable test case for passing a noescape closure to Objective-c which
escapes the closure.

We expect the program to crash with an explanation.

rdar://39682865
2018-05-01 07:24:19 -07:00
Arnold Schwaighofer
75bf101204 IRGen: Also handle nested types inside of extensions
rdar://39648725
2018-04-24 13:53:01 -07:00
Arnold Schwaighofer
a830acdbee IRGen: We need to make not of any parent decl in nested type decls
Such that we emit the parent's type metadata

rdar://39648725
2018-04-24 10:45:25 -07:00
Slava Pestov
39a65abf85 IRGen: Outlined thunks don't need to receive fixed-size metadata
They're not used inside the thunk so it's a waste passing them in, and
if they involve private types from a different translation unit we will
get a linking error from referencing the metadata accessor function.

Fixes the test case in <rdar://problem/39470607>, but the more general
problem remains.
2018-04-17 16:11:21 -07:00
Doug Gregor
80bb4505e4 Add crashing test case for rdar://problem/34584596. 2018-04-11 16:09:32 -07:00