Commit Graph

28382 Commits

Author SHA1 Message Date
Slava Pestov
d1125e957d Merge pull request #75995 from slavapestov/open-existential-recursive-properties
Track recursive properties and outer substitutions for opened existential environments
2024-08-20 22:04:36 -04:00
Allan Shortlidge
6d1a6c5f20 Sema: Avoid application extension platforms in if #available fix-its.
When the type checker noticed that a declaration with application extension
availability markup was used somewhere that it would be potentially unavailable
at runtime, the fix-it emitted by the compiler would check for the application
extension platform's availability:

```
if #available(macOSApplicationExtension 12, *) {
  // Use potentially unavailable declarations
}
```

This runtime check won't work. The fix-it should just suggest checking the
availability of the base, non-extension platform instead.

Resolves rdar://125860317.
2024-08-20 17:25:36 -07:00
Becca Royal-Gordon
fc81208293 Merge pull request #75919 from beccadax/objcimpl-selector-crasher 2024-08-20 14:04:28 -07:00
Slava Pestov
69bd0f0f1f AST: Remove OpaqueTypeArchetypeType::getCanonicalInterfaceType() 2024-08-20 17:00:25 -04:00
Slava Pestov
b434c9fb56 Merge pull request #75984 from slavapestov/clean-up-opened-archetype
Clean up OpenedArchetypeType construction and more
2024-08-20 16:52:55 -04:00
Pavel Yaskevich
f64bf5ff95 [AST] NFC: Rename ParameterInfoList::isPassedToSendableParameter to isSendableParameter
Just like other members of that type, `isPassedToSendableParameter` bit
set tracks information per parameter. The "passed" bit is applicable
to the argument rather than the parameter itself so it should bit kept
on the `AbstractClosureExpr`.
2024-08-20 13:17:04 -07:00
Slava Pestov
ff308e9510 AST: Remove TypeBase::openAnyExistentialType() 2024-08-20 12:15:27 -04:00
Slava Pestov
0c2f28fd3d AST: Remove GenericSignature parameter from OpenedArchetypeType::get() 2024-08-20 12:15:27 -04:00
Slava Pestov
5ac51b94b5 IDE: Refactor replaceArchetypesWithTypeVariables() to handle member types 2024-08-20 11:51:25 -04:00
Doug Gregor
d9f7d94ae9 Merge pull request #75413 from DougGregor/unsafe
Introduce `@unsafe` and the ability to prohibit use of unsafe entities
2024-08-20 06:14:39 -07:00
Allan Shortlidge
a288422a99 Sema: Fix override availability checking for protocols.
Given the following test case, override availability checking produced an
erroneus diagnostic:

```
@available(macOS 10.15, *)
protocol P {
    associatedtype A
    var a: A { get set }
}

@available(macOS 13.0, *)
protocol Q: P {
    // error: overriding _modify accessor for 'a' must be as available as
    //        declaration it overrides
    var a: A { get set }
}
```

The synthesized `_modify` accessor in `Q` is explicitly marked available in
macOS 13, which is less available than the `_modify` accessor in `P`. The
availability of `Q` should limit the required availability of the override and
prevent the diagnostic, but the implementation had a bug where it checked the
availability of the context's type instead of the contextual self type's
declaration. In the example, the context's type is `Self` which does not have
annotated availability.

Resolves rdar://133573707.
2024-08-19 22:23:55 -07:00
Slava Pestov
f4c3d8f7d6 Merge pull request #75966 from slavapestov/more-removal-of-root
Remove some usages of ArchetypeType::getRoot()
2024-08-19 21:18:05 -04:00
Allan Shortlidge
ed8bb98d27 Merge pull request #75899 from tshortli/member-import-visibility-spi
Sema: Only add `@_spiOnly` to import fix-its with a public access level
2024-08-19 14:35:47 -07:00
Doug Gregor
571859f294 Move "unsafe" diagnostics from errors to warnings
Warnings fit better with the approach we're going for, and can be
escalated to errors by `-warnings-as-errors` for clients that need it.
2024-08-19 14:34:00 -07:00
Doug Gregor
39f1e97bf9 [Safe mode] Diagnose uses of declarations involving unsafe types
When referencing a declaration, check whether any of the types in that
reference are unsafe. This can diagnose cases where the original
declaration either wasn't actually unsafe, or is being provided with
unsafe types via generics.
2024-08-19 14:33:09 -07:00
Doug Gregor
cccf6c1114 Introduce @unsafe and the ability to prohibit use of unsafe declarations
Allow any declaration to be marked with `@unsafe`, meaning that it
involves unsafe code. This also extends to C declarations marked with
the `swift_attr("unsafe")` attribute.

Under a separate experimental flag (`DisallowUnsafe`), diagnose any
attempt to use an `@unsafe` declaration or any unsafe language feature
(such as `unowned(unsafe)`, `@unchecked Sendable`). This begins to
define a "safe" mode in Swift that prohibits memory-unsafe constructs.
2024-08-19 14:33:07 -07:00
Slava Pestov
ce810605f8 Sema: Remove a usage of ArchetypeType::getRoot() 2024-08-19 16:55:10 -04:00
Slava Pestov
d4d85572ce Sema: typeEraseOpenedArchetypesWithRoot() => typeEraseOpenedArchetypesFromEnvironment() 2024-08-19 16:55:10 -04:00
Slava Pestov
76ec591fde AST: hasOpenedExistentialWithRoot() => hasLocalArchetypeFromEnvironment() 2024-08-19 16:55:10 -04:00
Allan Shortlidge
317b0e7abd Sema: Only add @_spiOnly to import fix-its with a public access level.
It doesn't make sense to add the `@_spiOnly` attribute to an `internal` import.

Part of rdar://126637855.
2024-08-19 10:58:49 -07:00
Hamish Knight
840ed6adff Merge pull request #75891 from hamishknight/fellthrough
[Sema] Improve handling of `fallthrough` in `if`/`switch` expressions
2024-08-19 17:59:24 +01:00
Slava Pestov
0e853a358e Merge pull request #75935 from slavapestov/remove-transform
AST: Replace remaining uses of Type::transform() with transformRec()
2024-08-17 09:11:52 -04:00
Allan Shortlidge
5a093c7c8b Sema: Refactor unavailable declaration diagnostics.
Consolidate code related to determining which kinds of diagnostics to emit and
platform names to display so that it is not duplicated between regular
declaration diagnostics and conformance diagnostics.

NFC.
2024-08-16 22:29:52 -07:00
Alex Hoppen
514f7bc92d Merge pull request #75793 from ahoppen/no-editor-mode
Remove `DiagnosticsEditorMode`
2024-08-16 21:25:54 -07:00
iMostfa
80a8a0746b Replace uses of the word "accessor" in diagnostics with user-facing terminology (#74462)
In this PR i worked on replacing the word accessor in diagnostics with more user-facing terminologies like setter, getter, didSet Observer, and members based on the context of the message.

in some messages i didn't need to pass DescriptiveDeclKind instead i just changed the text copy itself.

i also updated tests, so you might find it easier to check my changes this way.

Please let me know if there's something i should've done in a better way, and request changes if needed. !

i can squash my commits after reviewing getting the PR Reviewed, just to make it easier to be checked commit by commit

Resolves #55887
2024-08-16 16:29:30 -07:00
Becca Royal-Gordon
a0842b5f7a Fix crasher in objcImpl diagnostic
`fixDeclarationObjCName()` accepted optional selectors, but crashed if they were None. Make these parameters non-optional, treat an invalid `targetName` selector as “no name”, and adjust callers to pass non-optional values.

Re-enables decl/ext/objc_implementation.swift, which was disabled due to this bug.

Fixes rdar://128683206.
2024-08-15 16:26:03 -07:00
Mykola Pokhylets
50b1313175 Merge branch 'main' into mpokhylets/isolated-deinit
# Conflicts:
#	lib/SILGen/SILGenDistributed.cpp
#	lib/Sema/TypeCheckConcurrency.cpp
2024-08-15 16:58:43 +02:00
Ellie Shin
93f9a17c33 Merge pull request #75872 from swiftlang/elsh/pkg-switch-enum 2024-08-15 05:48:09 -07:00
Hamish Knight
ea8f801236 [Sema] Prevent fallthrough jumping out of if expressions
Impose the same limit we impose on other
forms of control flow statements (e.g `break`,
`continue`, `return`), where it cannot transfer
control out of the expression. This fixes a crash
where we'd fail to find a fallthrough nested in an
`if` expression. It is technically source breaking,
as we would have allowed the case where the `if`
expression is a directly nested result of an outer
`switch` expression, but I would be very surprised
if anyone is relying on that.

rdar://133845101
2024-08-14 19:59:05 +01:00
Hamish Knight
769805e714 [Sema] Fully allow fallthrough in switch expressions
Allow `fallthrough` to appear as the last statement
in the case of a `switch` expression. We already
allowed it in other positions, this was just an
oversight.

rdar://127670432
2024-08-14 19:59:05 +01:00
Hamish Knight
55aed16ee6 Requestify FallthroughStmt source and destination lookup
Follow a similar pattern to BreakTargetRequest
and ContinueTargetRequest.
2024-08-14 19:59:05 +01:00
Hamish Knight
4470814db8 [Sema] Recontextualize BreakStmt + ContinueStmt in lazy vars
I don't think this currently matters, but ensure
we re-contextualize BreakStmts and ContinueStmts
in RecontextualizeClosures since these statements
store DeclContexts.
2024-08-14 19:59:05 +01:00
Alex Hoppen
577727ad55 Remove DiagnosticsEditorMode
Migrate the last diagnostic to be independent of `DiagnosticEditorMode` and remove that option.

rdar://133111163
2024-08-14 11:24:31 -07:00
elsh
4f0f774856 Rename -> isInterfacePackageEffectivelyPublic 2024-08-14 01:35:24 -07:00
Ellie Shin
fadf6ec96c [Sema] Remove @unknown default requirement for package enums.
`@unknown default` in switch statements are required for resilient enums since they
might be modified with new fields in the future and modules defining the enums are
generally not built together with the consuming modules.

However, if the modules are in the same package, they are required to be built together,
thus the requirement for `@unknown default` can be skipped. This PR removes the need for
that, enabling less boilerplate. Note this change only impacts typecheck and not SIL gen.

Resolves rdar://130015149.
2024-08-13 17:06:51 -07:00
Ellie Shin
dc1c34dfa1 [Sema] Treat @usableFromInline package decls from interface as public and skip access checks
Resolves rdar://133319906
2024-08-13 17:01:19 -07:00
Allan Shortlidge
304f9c4bf0 AST: Look through missing imports in OverriddenDeclsRequest.
If `OverriddenDeclsRequest` fails to find any overridden declarations, query
again ignoring missing imports to find declarations that were excluded due to the
`MemberImportVisibility` feature being enabled.
2024-08-12 18:32:16 -07:00
Alex Hoppen
bdc6fc60d2 Merge pull request #75666 from ahoppen/share-is-static
[IDE] Call into `matchWitnessStructure` to check if we should inherit a comment from an overridden declaration
2024-08-12 18:02:56 -07:00
Alex Hoppen
328e8af700 Merge pull request #75792 from ahoppen/no-editor-mode-switch
[Sema/IDE] Emit same diagnostics for missing switch cases independent of editor mode
2024-08-12 17:24:34 -07:00
Alex Hoppen
f169bdbd54 [IDE] Call into matchWitnessStructure to check if we should inherit a comment from an overridden declaration 2024-08-12 14:26:01 -07:00
Alex Hoppen
7d7eb6e61d [Sema/IDE] Emit same diagnostics for missing switch cases independent of editor mode 2024-08-12 14:01:22 -07:00
Slava Pestov
b601c294ac AST: Replace remaining uses of Type::transform() with transformRec() 2024-08-12 16:05:43 -04:00
Mykola Pokhylets
1120beeadb Reject isolation attributes on deinit in value types 2024-08-12 12:50:17 +02:00
Rintaro Ishizaki
a07caa8ba5 Merge pull request #74941 from rintaro/macros-leak-rdar131048379
[Macros] Fix memory leak
2024-08-10 15:46:12 -07:00
Alex Hoppen
3ed457ab3b [Sema] Move getDocCommentProvidingDecl and getCascadingDocComment from AST to Sema
This allows use to re-use logic from Sema in those requests.

This commit just moves functions around and does not change any functionality.
2024-08-09 11:38:26 -07:00
Slava Pestov
375363a473 AST: Move global conformance lookup entry points to ConformanceLookup.h 2024-08-08 23:35:58 -04:00
Allan Shortlidge
6e4e111d8a Merge pull request #75766 from tshortli/superfluous-not-imported-here-diags
Sema: Avoid emitting superfluous resilience diagnostics with `MemberImportVisibility`
2024-08-08 09:20:45 -07:00
Sophia Poirier
8b43ac6a18 Merge pull request #75761 from sophiapoirier/global-concurrency-checking-refactor
[Concurrency] refactor GlobalConcurrency checking from ActorIsolationRequest to DeclChecker
2024-08-07 21:10:59 -07:00
Allan Shortlidge
7e1eac7f08 Sema: Avoid emitting superfluous resilience diagnostics with MemberImportVisibility.
When `MemberImportVisibility` is enabled, if the import that would bring a
member declaration into scope is missing it is diagnosed as an error. The
existing resilience diagnostics that would also diagnose the same problem in
contexts that are visible in the module interface are therefore superflous with
the feature enabled.
2024-08-07 18:17:10 -07:00
Alex Hoppen
8edb57c756 Merge pull request #75667 from ahoppen/build-issues-live-issues
[Sema/SourceKit] Emit same diagnostics for missing protocol requirements on the command line and in SourceKit
2024-08-07 17:24:47 -07:00