Commit Graph

62 Commits

Author SHA1 Message Date
Doug Gregor
225e562dda Requestify the #if computation using SwiftIfConfig
We're not caching this now, but it lets us dodge annoying layering
issues because ASTGen (where this is available) sits on top of the C++
parser, which needs to call it.
2024-08-24 21:31:41 -07:00
Hamish Knight
246f09a1e1 [AST] Improve FailStmt source location computation
Avoid forming invalid source ranges when
`ReturnLoc` is invalid. Also introduce a utility
to make this kind of range computation easier,
and use it in a couple of other cases.
2024-01-23 19:30:32 +00:00
swift-ci
57420eb1af Merge remote-tracking branch 'origin/main' into rebranch 2022-07-27 11:35:49 -07:00
3405691582
c5e9e20828 Include assert.h manually in SourceLoc.h.
On the BSDs when building with bootstrapping and therefore modules enabled,
this will result in a "declaration here is not visible" error. This is
_possibly_ because the assert implementation is not reexported from LLVM,
maybe due to libc differences. Regardless, this fixes the problem and
should be relatively inocuous to unconditionally include.
2022-07-26 17:46:25 -04:00
swift_jenkins
3dd997af43 Merge remote-tracking branch 'origin/main' into next 2022-03-02 09:42:00 -08:00
Ben Langmuir
5a5dd13ca1 Include what you use: Optional and Hashing
Add a few includes of Optional.h and Hashing.h. These files are failing
ot build in the "next" branch due to changes in llvm's own includes, but
it's general goodness to include them on main as well.
2022-02-24 13:47:04 -08:00
Ben Barham
bd4b73755b [next] Update DenseMapInfo declarations
llvm-project 4c484f11d355e4293f7b245a9330f0a1e89630ac updated the
`DenseMapInfo` template to take a SFINAE template parameter.
2021-11-18 21:58:56 +10:00
Fredrik Wieczerkowski
7a73c99510 Migrate VariableTypeCollector to SourceRange
- Add SourceRange::contains and SourceRange::overlaps
- Use SourceRange in VariableTypeCollector
2021-06-21 19:33:52 +02:00
Michael Gottesman
1227693d29 [opt-remark-gen] Teach OptRemarkGen how to emit diagnostics about exclusivity.
For example, now we get the following diagnostic on globals:

 public func getGlobal() -> Klass {
     return global // expected-remark @:5 {{retain of type 'Klass'}}
                   // expected-note @-5:12 {{of 'global'}}
+                  // expected-remark @-2:12 {{begin exclusive access to value of type 'Klass'}}
+                  // expected-note @-7:12 {{of 'global'}}
+                  // expected-remark @-4 {{end exclusive access to value of type 'Klass'}}
+                  // expected-note @-9:12 {{of 'global'}}
+
 }

and for classes when we can't eliminate the access:

+func simpleInOut() -> Klass {
+    let x = Klass() // expected-remark @:13 {{heap allocated ref of type 'Klass'}}
+                    // expected-note @-1:9 {{of 'x'}}
+    simpleInOutUser(&x.next) // expected-remark @:5 {{begin exclusive access to value of type 'Optional<Klass>'}}
+                             // expected-note @-3:9 {{of 'x.next'}}
+                             // expected-remark @-2:28 {{end exclusive access to value of type 'Optional<Klass>'}}
+                             // expected-note @-5:9 {{of 'x.next'}}
+    return x
+}
2021-03-28 13:39:13 -07:00
Brent Royal-Gordon
99faa033fc [NFC] Standardize dump() methods in frontend
By convention, most structs and classes in the Swift compiler include a `dump()` method which prints debugging information. This method is meant to be called only from the debugger, but this means they’re often unused and may be eliminated from optimized binaries. On the other hand, some parts of the compiler call `dump()` methods directly despite them being intended as a pure debugging aid. clang supports attributes which can be used to avoid these problems, but they’re used very inconsistently across the compiler.

This commit adds `SWIFT_DEBUG_DUMP` and `SWIFT_DEBUG_DUMPER(<name>(<params>))` macros to declare `dump()` methods with the appropriate set of attributes and adopts this macro throughout the frontend. It does not pervasively adopt this macro in SILGen, SILOptimizer, or IRGen; these components use `dump()` methods in a different way where they’re frequently called from debugging code. Nor does it adopt it in runtime components like swiftRuntime and swiftReflection, because I’m a bit worried about size.

Despite the large number of files and lines affected, this change is NFC.
2019-10-31 18:37:42 -07:00
Jordan Rose
b32e82c720 More idiomatic use of llvm::hash_combine in many places (#27497)
- No need to hash input values first
- Pass many values to a single hash_combine to save on intermediates
- Use hash_combine_range instead of a loop of hash_combines

No functionality change.
2019-10-04 13:08:24 -07:00
Doug Gregor
ff2cb3305d [Type checker] Factor "type check function body until" into a request.
Extend the "type check function body" request to also cover the case
where we have a specific ending source location. Fold all of this
functionality into a single request, so we consistently go through a
request to compute a type-checked function body.
2019-07-12 17:40:53 -07:00
Adrian Prantl
ff63eaea6f Remove \brief commands from doxygen comments.
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.

Patch produced by

      for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
2018-12-04 15:45:04 -08:00
David Zarzycki
8b86fdef1b [NFC] Rule of five/zero feedback 2018-11-26 16:48:24 -05:00
David Zarzycki
bf7f91b834 [Misc] NFC: Fix -Wdefaulted-function-deleted warnings 2018-11-17 08:30:59 -05:00
Harlan
dc1bc823e6 [InterfaceGen] Remove #ifs from default arguments (#19075)
* [InterfaceGen] Remove #ifs from default args

This patch removes all #if configs form the bodies of default arguments,
which can contain multiline closures, while preserving the bodies of the
clauses that are active.

This code is generalized and should "just work" for inlinable function
bodies, which will come in a later patch.

* Address review comments

* Fix and test CharSourceRange.overlaps

* Fix CharSourceRange::print to respect half-open ranges
2018-08-31 20:18:48 -07:00
Mingsheng Hong
83d4bcae38 Fixed compilation errors. 2018-08-03 10:56:30 -07:00
Mingsheng Hong
61b20c8071 Also added DenseMapInfo specialization for SourceLoc, so that call-site can
decide whether to use a map key based on SourceLoc or SourceRange.
2018-08-02 16:04:43 -07:00
Mingsheng Hong
0a09541bcb Make swift::SourceRange usable as a key type for DenseSet/DenseMap.
One use case is using DenseSet to manage a set of source locations, so that we
emit at most one compiler diagnostic per location (see
https://github.com/apple/swift/pull/18402).
2018-07-31 14:31:10 -07:00
Alex Hoppen
8998b27dd4 [incrParse] Add coloured output indicating which code got reused 2018-05-22 08:52:34 -07:00
Alex Hoppen
746bfc6d59 [Refactoring] Add refactoring action to move type members to extension (#12795)
This implements SR-6297.
2017-11-09 11:08:34 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Jordan Rose
84e09a8d24 Add == for SourceRange and CharSourceRange. NFC. 2016-05-26 17:55:19 -07:00
Chris Lattner
821c2cb98f Merge pull request #1796 from danra/swift_basic_sanitize
Canonicalize swift header files headers and footers
2016-03-29 17:31:53 -07:00
Dmitri Gribenko
47fe51ddd0 Merge pull request #1836 from danra/patch-31
operator!= DRY
2016-03-25 00:48:54 -07:00
Chris Lattner
833f73a00b Merge pull request #1838 from danra/patch-33
Remove extra spaces in empty-body ctors
2016-03-24 22:52:59 -07:00
Chris Lattner
e0c9c1a163 Merge pull request #1840 from danra/patch-35
Compact getEnd implementation
2016-03-24 22:52:22 -07:00
danra
6d14912cfa Compact getEnd implementation 2016-03-24 16:38:30 +02:00
danra
21f21e395b isInvalid methods DRY 2016-03-24 16:32:02 +02:00
danra
5f5786a725 Remove extra spaces in empty-body ctors
Currently some empty-body ctors in the file have a space, some don't. Canonized it.
2016-03-24 16:27:13 +02:00
danra
87fcb1bbb3 operator!= DRY 2016-03-24 16:18:35 +02:00
Dan Raviv
29d76f3b68 Canonize swift header files headers and footers
- Added missing ifdef guard in PointerIntEnum header
- Consistent naming convention for ifdef guards
- Consistent 'end namespace swift'
- Consistent single EOL at end of header files
2016-03-23 09:04:12 +02:00
practicalswift
1339b5403b Consistent use of header comment format.
Correct format:
//===--- Name of file - Description ----------------------------*- Lang -*-===//
2016-01-04 13:26:31 +01:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Adrian Prantl
8ab1e2dd50 Unify debug scope and location handling in SILInstruction and SILBuilder.
The drivers for this change are providing a simpler API to SIL pass
authors, having a more efficient of the in-memory representation,
and ruling out an entire class of common bugs that usually result
in hard-to-debug backend crashes.

Summary
-------

SILInstruction

Old                   New
+---------------+     +------------------+    +-----------------+
|SILInstruction |     |SILInstruction    |    |SILDebugLocation |
+---------------+     +------------------+    +-----------------+
| ...           |     | ...              |    | ...             |
|SILLocation    |     |SILDebugLocation *| -> |SILLocation      |
|SILDebugScope *|     +------------------+    |SILDebugScope *  |
+---------------+                             +-----------------+

We’re introducing a new class SILDebugLocation which represents the
combination of a SILLocation and a SILDebugScope.
Instead of storing an inline SILLocation and a SILDebugScope pointer,
SILInstruction now only has one SILDebugLocation pointer. The APIs of
SILBuilder and SILDebugLocation guarantees that every SILInstruction
has a nonempty SILDebugScope.

Developer-visible changes include:

SILBuilder
----------

In the old design SILBuilder populated the InsertedInstrs list to
allow setting the debug scopes of all built instructions in bulk
at the very end (as the responsibility of the user). In the new design,
SILBuilder now carries a "current debug scope" state and immediately
sets the debug scope when an instruction is inserted.
This fixes a use-after-free issue with with SIL passes that delete
instructions before destroying the SILBuilder that created them.

Because of this, SILBuilderWithScopes no longer needs to be a template,
which simplifies its call sites.

SILInstruction
--------------

It is neither possible or necessary to manually call setDebugScope()
on a SILInstruction any more. The function still exists as a private
method, but is only used when splicing instructions from one function
to another.

Efficiency
----------

In addition to dropping 20 bytes from each SILInstruction,
SILDebugLocations are now allocated in the SILModule's bump pointer
allocator and are uniqued by SILBuilder. Unfortunately repeat compiles
of the standard library already vary by about 5% so I couldn’t yet
produce reliable numbers for how much this saves overall.

rdar://problem/22017421
2015-11-19 09:31:26 -08:00
Xi Ge
f3c5692092 Add the missing include.
Swift SVN r32322
2015-09-29 23:47:15 +00:00
Xi Ge
71fdf73663 Allow CharSourceRange to peek the underlying text, need this for rdar://22857642
Swift SVN r32320
2015-09-29 23:32:40 +00:00
Xi Ge
42aeba54a4 Suggested by Jordan and Michael, use '=delete' to prevent constructor from being called.
Swift SVN r32040
2015-09-17 18:08:20 +00:00
Xi Ge
2ba154093d Make sure a problematic constructor will not be added in future.
Swift SVN r32039
2015-09-17 17:40:37 +00:00
Xi Ge
7f6a8b1315 Remove the constructor of CharSourceRange that takes SourceRange;
And add a utility function at lexer that converts SourceRange to CharSourceRange.

Swift SVN r32023
2015-09-17 01:15:34 +00:00
Dave Abrahams
51637bb411 New capabilities for CharSourceRange
dump(), overlaps(other), widen(other), and construction from a
SourceRange.

(Pair-programmed with Dmitri Hrybenko)

Swift SVN r26465
2015-03-24 00:50:42 +00:00
Argyrios Kyrtzidis
f8e5b6b3e2 [IDE] Modify structure testing to tag the relevant ranges directly on the source,
instead of outputting the info with lines/columns.

This make the structure more clear and testing more convenient.

Swift SVN r25865
2015-03-09 00:42:38 +00:00
Jordan Rose
29f8c25d63 Move #line state into the Parser and out of the SourceManager.
As part of this change, allow #line directives to extend to the end of the
file, rather than requiring a reset.

Note that #line regions that start or end within function bodies will not
behave correctly when in delayed parsing modes. This was true before and
after this commit. (#line regions contained entirely within a function and
not within any other #line regions should be fine.)

Swift SVN r20571
2014-07-25 23:01:43 +00:00
Dmitri Hrybenko
c1d96e579e Comment parsing: allow parsing comments with invalid source locations -- these
come from serialized modules


Swift SVN r15104
2014-03-15 14:58:29 +00:00
Sonny Falk
df693fd744 Make the CharSourceRange constructor take the SourceManager parameter as const.
Swift SVN r9596
2013-10-22 20:48:15 +00:00
Argyrios Kyrtzidis
0d7fc0aa1d [ide] Use the newly introduce CharSourceRange inside ide::SyntaxNode.
Swift SVN r7174
2013-08-12 20:58:20 +00:00
Dmitri Hrybenko
70f2b64ad9 Add CharSourceRange -- a half-open character range, which will be used in IDE
integration

Motivation: libIDE clients should be simple, and they should not have to
translate token-based SourceRanges to character locations.

This also allows us to remove the dependency of DiagnosticConsumer on the
Lexer.  Now the DiagnosticEngine translates the diagnostics to CharSourceRanges
and passes character-based ranges to the DiagnosticConsumer.


Swift SVN r7173
2013-08-12 20:15:51 +00:00
Dmitri Hrybenko
efd688dcd9 Now findBufferContainingLoc() can not fail, so store Buffer IDs in unsigned
variables.


Swift SVN r7121
2013-08-10 02:12:59 +00:00
Dmitri Hrybenko
9c57f8454c Do the final cleanups and make SourceLoc::Value private
Swift SVN r7115
2013-08-09 23:52:01 +00:00