Commit Graph

23 Commits

Author SHA1 Message Date
Pavel Yaskevich
be0169042d [Sema] ConstnessChecker: Look through function conversions while checking arguments
In strict concurrency mode some calls could reference a declaration that
is  wrapped in one or more function conversion expressions to apply
concurrency related attributes or erase them (such as `@Sendable` or
`@MainActor`). This shouldn't impact constness checking and the checker
should look through such conversions.

Resolves: rdar://148168219
(cherry picked from commit b484e9645d)
2025-04-23 14:18:11 -07:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Hamish Knight
16cfca4186 [ASTWalker] NFC: Rename SkipChildren -> SkipNode
This better describes what the action currently
does, and allows us to re-introduce `SkipChildren`
with the correct behavior.
2024-02-05 15:27:25 +00:00
Slava Pestov
9ebb5f2e03 AST: Rename VarDecl::getType() to VarDecl::getTypeInContext()
This is a futile attempt to discourage future use of getType() by
giving it a "scary" name.

We want people to use getInterfaceType() like with the other decl kinds.
2023-08-04 14:19:25 -04:00
Pavel Yaskevich
773513a5c7 [Sema] Run structural/availability diagnostics on tap bodies
Since interpolations are now type-checked using conjunctions
these diagnostics could be rank as part of the root expression
or statement verification.
2023-07-07 19:50:46 +02:00
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
Hamish Knight
4716f61fba [AST] Introduce explicit actions for ASTWalker
Replace the use of bool and pointer returns for
`walkToXXXPre`/`walkToXXXPost`, and instead use
explicit actions such as `Action::Continue(E)`,
`Action::SkipChildren(E)`, and `Action::Stop()`.
There are also conditional variants, e.g
`Action::SkipChildrenIf`, `Action::VisitChildrenIf`,
and `Action::StopIf`.

There is still more work that can be done here, in
particular:

- SourceEntityWalker still needs to be migrated.
- Some uses of `return false` in pre-visitation
methods can likely now be replaced by
`Action::Stop`.
- We still use bool and pointer returns internally
within the ASTWalker traversal, which could likely
be improved.

But I'm leaving those as future work for now as
this patch is already large enough.
2022-09-13 10:35:29 +01:00
Josh Learn
f748c84cf1 [Sema][MiscDiag] Fix constantness diag to handle result builder patterns
We currently have a problem with how constantness diagnostics
traverse the AST to look for function calls to diagnose. We
special case closure bodies and don't check them (unless they're
single expression closures) because closure bodies are type-
checked separately and will be covered later. This poses a problem
in certain AST structures, such as what we see with result builders,
because the call expressions are rooted in declarations, which aren't
checked in the closure body type-checking covered by MiscDiag.

This patch fixes the problem by manually checking all closure bodies
and stopping misc diagnostics from checking the bodies separately.

rdar://85737300
2021-12-15 18:26:29 -08:00
Pavel Yaskevich
77ab650f59 [TypeChecker/Constness] Diagnostics: Walk into multi-statement closures when inference is enabled
When multi-statement closure inference is enabled it's body is
type-checked together with enclosing context, so they could be
walked directly just like single-expressions ones.
2021-12-03 10:55:54 -08:00
Pavel Yaskevich
bc54bc6bb7 Revert "[TypeChecker] SE-0326: Enable multi-statement closure inference by default" 2021-11-29 17:26:08 -08:00
Pavel Yaskevich
9509eef7a3 [TypeChecker/Constness] Diagnostics: Walk into multi-statement closures when inference is enabled
When multi-statement closure inference is enabled it's body is
type-checked together with enclosing context, so they could be
walked directly just like single-expressions ones.
2021-11-15 16:42:05 -08:00
Kuba (Brecka) Mracek
87cc490c57 Allow identification of OSLogMessage by a @_semantics attribute instead of just name (#39455) 2021-09-27 13:54:40 -07:00
Hamish Knight
0574da382d [Sema] Adopt ArgumentList 2021-09-01 18:40:27 +01:00
Josh Learn
6c881f52a3 [Sema] Fix constantness diagnostics for single expression closures
Due to the way miscellaneous diagnostics work with closure bodies, the
function argument constantness sema check does not produce proper
diagnostics for single-expression closures. This change fixes the
problem by having the ASTWalker manually walk in the closure body
if it is a single expression.

rdar://65577070
2021-06-23 19:43:40 -04:00
Azoy
9ed732f0ab Introduce isDecl and getDeclType
fix enum logic issue

fix tests

guard against null types
2021-04-20 02:22:16 -04:00
Josh Learn
a6da8a8899 Support constant diagnostics on constructors
This change includes a fix to allow the diagnostics
for constantness in function arguments to work properly
for constructors. This change also includes some minor
code cleanup in the constantness diagnostic pass.
2021-03-31 11:06:55 -07:00
Josh Learn
816d186d92 Extend compile-time constantness check to support constant Ranges
Currently the function parameter constantness check for functions
annotated with @_semantics("oslog.requires_constant_argument") does
not support ranges (e.g. 0...5, 0..<5). Ranges like this are
considered binary expressions by the compiler. This change adds
support for accepting binary expressions as constant arguments
as long as both arguments to the expression are constant.

rdar://71822563
2021-03-25 11:51:44 -07:00
Ravi Kandhadai
49b0984e19 [Sema][os_log] Allow wrapping os_log strings within constant evaluable functions.
As of now, the sema checks for os_log allow only string interpolations to be passed
to the log calls. E.g. logger.log(foo("message")) would not be allowed. This PR
relaxes this requirement and allows it as long as foo is annotated as
@_semantics("constant_evaluable").

<rdar://problem/65215054>
2020-07-15 10:54:08 -07:00
Anthony Latsis
9fd1aa5d59 [NFC] Pre- increment and decrement where possible 2020-06-01 15:39:29 +03:00
Joe Groff
c5863ac0f3 SILOptimizer: Constant fold the _kvcKeyPathString of literal key paths.
Eliminate the intermediate key path object when a literal key path is passed to a function that
just wants its KVC string to pass down to an ObjC API.
2020-05-07 13:33:01 -07:00
Ravi Kandhadai
2e0457ab0d [OSLog Diagnostics] Improve diagnostics emitted in the SIL and Sema diagnostic passes
for the os log APIs. These improvements are aimed at covering some rare corner cases.
2020-04-18 15:29:22 -07:00
Ravi Kandhadai
03d726c5c2 [Sema Diagnostics][OSLog] Make the miscellaneous diagnostics that
checks the constantness of arguments passed to the new os log APIs
ignore the log level and log object which can be dynamic.
2020-04-17 14:38:13 -07:00
Ravi Kandhadai
b57a1d7c0e [Sema] Add miscellaneous sema diagnostics to check that the new os log
APIs and atomic operations are passed compile-time constants for
certain arguments.
2020-04-06 18:41:13 -07:00