Commit Graph

168 Commits

Author SHA1 Message Date
Michael Gottesman
6fee59bd6a [semantic-arc-opts] Implement @owned phi web elimination for phi webs with a single phi node that only have copy_value introducers.
This is the most simple initial version that I can commit. The hope is that this will help to bring this up in a nice way.

I am going to handle the multiple phi node and load [copy] case later to reduce
code churn.

<rdar://problem/56720436>
2020-03-09 16:04:48 -07:00
Michael Gottesman
bc8a4db572 Revert "Revert "[basic] Add a simple vector backed 2 stage multi map.""
This reverts commit f071cf133a.

With ASAN fixes.
2020-02-16 23:14:57 -08:00
John McCall
319cc795d8 Add a simple TaggedUnion defined in terms of ExternalUnion. NFC. 2020-02-04 15:05:39 -05:00
Andrew Trick
f071cf133a Revert "[basic] Add a simple vector backed 2 stage multi map." 2020-01-07 16:05:21 -08:00
Michael Gottesman
96a0c7931d [basic] Add a simple vector backed 2 stage multi map.
I have been using this in a bunch of places in the compiler and rather than
implement it by hand over and over (and maybe messing up), this commit just
commits a correct implementation.

This data structure is a map backed by a vector like data structure. It has two
phases:

1. An insertion phase when the map is mutable and one inserts (key, value) pairs
into the map. These are just appeneded into the storage array.

2. A frozen stage when the map is immutable and one can now perform map queries
on the multimap.

The map transitions from the mutable, thawed phase to the immutable, frozen
phase by performing a stable_sort of its internal storage by only the key. Since
this is a stable_sort, we know that the relative insertion order of values is
preserved if their keys equal. Thus the sorting will have created contiguous
regions in the array of values, all mapped to the same key, that are insertion
order. Thus by finding the lower_bound for a given key, we are guaranteed to get
the first element in that continguous range. We can then do a forward search to
find the end of the region, allowing us to then return an ArrayRef to these
internal values.

The reason why I keep on finding myself using this is that this map enables one
to map a key to an array of values without needing to store small vectors in a
map or use heap allocated memory, all key, value pairs are stored inline (in
potentially a single SmallVector given that one is using SmallFrozenMultiMap).
2020-01-06 16:39:42 -08:00
Jordan Rose
8b8c88e258 Improve swift::TransformRange enough to delete TransformArrayRef
We have a lot of "transform a range" types already:
llvm::mapped_iterator, swift::TransformRange and
swift::TransformIterator, and swift::ArrayRefView for static
transformations. This gets rid of one more layer without losing
any real functionality.
2019-10-02 10:23:05 -07:00
Marc Rasi
af37b2cf5e fix ASAN in cache test 2019-07-18 15:48:41 -07:00
Marc Rasi
cd2556d07d fix memory leak in swift::sys::Cache
It fails to destroy a key in one case.
2019-07-09 11:14:48 -07:00
Michael Munday
ce3aff12da [Basic] Always serialize integers in little-endian byte order
This change fixes the ExponentialGrowthAppendingBinaryByteStream
tests on big endian machines.

Force ExponentialGrowthAppendingBinaryByteStreams to use little-
endian byte order. We always used little-endian byte order anyway
and it seems very unlikely we'll need the flexibility to make the
stream big-endian in the future. The benefit of this is that we
can use portable APIs while still allowing the compiler to remove
conditional byte swaps.

Also replace writeRaw with writeInteger and make it explicitly
little-endian to make the API cleaner and more portable.
2019-07-02 11:36:58 -04:00
Michael Munday
192bcb2007 Basic: Use APInt to implement ClusteredBitVector
Simplify the implementation of ClusteredBitVector by using an APInt
to represent the raw bits. This simplification will make it easier
to incrementally move to a representation of bit vectors that works
on both big- and little-endian machines.

This commit also removes reserve and reserveExtra from the API
since they were only used in one place and no longer have any effect
because memory allocation is now handled by the APInt class.
2019-06-04 14:05:10 +01:00
Michael Munday
d3262ec10d [IRGen] Remove SetBitEnumerator from ClusteredBitVector
The change replaces 'set bit enumeration' with arithmetic
and bitwise operations. For example, the formula
'(((x & -x) + x) & x) ^ x' can be used to find the rightmost
contiguous bit mask. This is essentially the operation that
SetBitEnumerator.findNext() performed.

Removing this functionality reduces the complexity of the
ClusteredBitVector (a.k.a. SpareBitVector) implementation and,
more importantly, API which will make it easier to modify
the implementation of spare bit masks going forward. My end
goal being to make spare bit operations work more reliably on
big endian systems.

Side note:

This change modifies the emit gather/scatter functions so that
they work with an APInt, rather than a SpareBitVector, which
makes these functions a bit more generic. These functions emit
instructions that are essentially equivalent to the parallel bit
extract/deposit (PEXT and PDEP) instructions in BMI2 on x86_64
(although we don't emit those directly currently). They also map
well to bitwise manipulation instructions on other platforms (e.g.
RISBG on IBM Z). So we might find uses for them outside spare bit
manipulation in the future.
2019-05-17 11:55:06 +01:00
Jordan Rose
f6c7973911 Teach -verify-apply-fixes to handle overlapping fix-its (#23970)
...by coalescing duplicates and dropping conflicts. Both cases can
happen with "expected-error 2 {{...}}": we might get multiple fix-its
providing the same new message, or one message might have diverged
into two, giving us incompatible changes.
2019-04-12 13:19:54 -07:00
Adrian Prantl
4b1532cddc Rename swift::Demangle::archetypeName() to swift::Demangle::genericParameterName(). 2019-03-01 08:02:28 -08:00
Adrian Prantl
b36c646914 Allow for passing a custom Archetype naming schema to the demangler.
LLDB would like to substitute the original Archetype names from the
source code when demangling symbols instead of the confusing generic
'A', 'B', ...

<rdar://problem/48259889>
2019-02-28 14:01:38 -08: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
Erik Eckstein
39bb14b094 change mangling prefix from $S to $s
This is the final ABI mangling prefix

rdar://problem/38471478
2018-09-19 13:55:11 -07:00
Davide Italiano
e4d9813b40 [Demangler] Adjust the implementation of isObjCSymbol().
Pointed out by Jordan.
2018-09-18 13:48:51 -07:00
Davide Italiano
dbe5ee77b8 [Demangler] Implement isObjCSymbol().
This function can be queried to find out whether the passed
mangled name is an Objective-C symbol. This will be used
in the debugger to replace an hardcoded check that would
break if the mangling prefix changed.

<rdar://problem/44467875>
2018-09-18 11:32:16 -07:00
Alex Hoppen
33d86d5cb6 [byteTree] Write fixed sized data using an optimized form
If we know the size of a type at compile time (like we do for all the
integer types), it is cheaper to assign the data buffer directly instead
of using a memcpy.
2018-08-24 15:27:23 -07:00
Alex Hoppen
49f2e14094 [swiftBasic] Use a SmallVector as the underlying storage for ExponentialGrowthAppendingBinaryByteStream 2018-08-23 09:00:27 -07:00
Alex Hoppen
ff68452301 [swiftBasic] Introduce an exponentially growing appending binary stream
It is more efficient than llvm::AppendingBinaryByteStream if a lot of
small data gets appended to it because it doesn't need to resize its
buffer on each write.
2018-08-23 08:14:02 -07:00
Alex Hoppen
ac512d4341 [libSyntax] Add a reference counted version of OwnedString
We cannot use unowned strings for token texts of incrementally parsed
syntax trees since the source buffer to which reused nodes refer will
have been freed for reused nodes. Always copying the token text whenever
OwnedString is passed is too expensive. A reference counted copy of the
string allows us to keep the token's string alive across incremental
parses while eliminating unnecessary copies.
2018-08-13 15:37:53 -07:00
Bob Wilson
8e330ee344 NFC: Fix indentation around the newly renamed LLVM_DEBUG macro.
Jordan used a sed command to rename DEBUG to LLVM_DEBUG. That caused some
lines to wrap and messed up indentiation for multi-line arguments.
2018-07-21 00:56:18 -07:00
Jordan Rose
cefb0b62ba Replace old DEBUG macro with new LLVM_DEBUG
...using a sed command provided by Vedant:

$ find . -name \*.cpp -print -exec sed -i "" -E "s/ DEBUG\(/ LLVM_DEBUG(/g" {} \;
2018-07-20 14:37:26 -07:00
Alex Hoppen
6635be10ea [libSyntax] Add UserInfo to json::Output
This will allow us to customize the serialization of a syntax tree like
not serializing the node's IDs.
2018-07-18 13:35:10 -07:00
Alex Hoppen
60feeac01c [libSyntax] Copy the text of a syntax node
Since we are reusing syntax nodes as part of incremental parsing, we
cannot rely on the buffer always outliving the syntax nodes.
2018-07-18 13:35:10 -07:00
David Zarzycki
95473a10d7 [Misc] NFC: Fix random build warnings
Unused variables/methods, language extensions, extra semicolons, intentional
self assignment, platform specific quirks, etc.
2018-04-30 12:52:43 -04:00
Andrew Trick
9923d5d9cf Fix usability issues with BlotVector.
- Add const getItems().

- Fix const find().

- erase() returns a boolean.

- Set erase() should not perform two lookups.

The implementation is covered by the unit tests with a small addition.

Other trivial API changes are trivially tested in upcoming commits.
2018-03-31 17:39:54 -07:00
swift-ci
1a3161ac85 Merge remote-tracking branch 'origin/master' into master-llvm-swift5-transition 2018-01-30 00:08:37 -08:00
Rintaro Ishizaki
d7470100a4 [JSONSerialization] Add basic unit tests for JSONSerialization 2018-01-30 15:40:17 +09:00
Bob Wilson
390058972a [master-next] Use PRIVATE in target_link_libraries for executables
This is needed to work with LLVM r319840.
2017-12-06 21:55:22 -08:00
Ben Langmuir
4ce33ced0d Fix sys::Cache for ref-counted values which caused memory leaks in SourceKit
Our libcache implementation of swift::sys::Cache was broken for
ref-counted values (which are used by e.g. the SourceKit ASTManager).
It would always `retain(value)` in `set(key, value)`, but under the hood
libcache shares values, so we would only get one `release(value)` if the
same value was used across multiple keys, or if the same value *and* key
were set multiple times.

This was causing us to never release ASTs cached by SourceKit even when
the underlying libcache purged itself under memory pressure.

rdar://problem/21619189
2017-07-06 13:56:58 -07:00
Slava Pestov
26be491a3d Basic: Fix a warning 2017-03-17 15:01:25 -07:00
Erik Eckstein
5e80555c9b demangler: put the demangler into a separate library
Previously it was part of swiftBasic.

The demangler library does not depend on llvm (except some header-only utilities like StringRef). Putting it into its own library makes sure that no llvm stuff will be linked into clients which use the demangler library.

This change also contains other refactoring, like moving demangler code into different files. This makes it easier to remove the old demangler from the runtime library when we switch to the new symbol mangling.

Also in this commit: remove some unused API functions from the demangler Context.

fixes rdar://problem/30503344
2017-03-09 13:42:43 -08:00
Erik Eckstein
437d4da38d Demangling: Remove StringRef-versions of demangling functions from demangle_wrappers because they are now available in Demangle itself.
This is just refactoring. NFC.
2017-02-24 15:19:18 -08:00
Hugh Bellamy
b564a917be Port swiftSyntax to Windows 2017-02-21 08:24:56 +07:00
Hugh Bellamy
d4cebb5947 Don't use a uint8_t random distruction in DiverseStack unit tests 2017-02-18 16:18:10 +07:00
Michael Gottesman
de47e4fe3a [diverse-stack] Add some more helper methods to diverse stack and unittests for that functionality.
rdar://29791263
2017-02-14 11:14:16 -08:00
practicalswift
3e40296cfa [gardening] Fix inconsistent headers 2017-02-13 15:21:52 +01:00
Michael Gottesman
3c58e42983 Add unittests for DiverseStack. 2017-02-09 22:30:44 -08:00
Michael Gottesman
6d1058cf0b [gardening] Quiet verbose output from BlotMapVectorTest unless it is requested via llvm debug. 2017-02-09 22:23:22 -08:00
Michael Gottesman
e678f4979b [gardening] Add swift license headers to all files in ./unittests/Basic/*. 2017-02-09 22:02:42 -08:00
Michael Gottesman
942f7eb5e2 [gardening] Sort unittest names in ./unittests/Basic/CMakeLists.txt. 2017-02-09 21:55:29 -08:00
Michael Gottesman
af61ed85a4 [gardening] Standardize ./unittests/Basic so that all tests have the Test.cpp suffix. 2017-02-09 21:50:57 -08:00
Michael Gottesman
79c4034bb1 [gardening] Split ADTTests.cpp into separate test files. 2017-02-09 21:48:30 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Michael Gottesman
b95a34a797 Add a new utility called reverse_range(start, end) that returns a reverse range from (start, end]. 2017-01-03 17:01:20 -08:00
practicalswift
a8df7410cb [gardening] Use the correct Swift URL 2016-12-20 10:06:28 +01:00
Michael Gottesman
6f3c1ee658 Add a new ArrayRefView like structure called TransformArrayRef.
The difference is that TransformArrayRef stores its function as an std::function
instead of using a template parameter. This is useful in situations where one
wants to define such a type in a header on forward declared pointers. If one had
to define the function to be used as a template parameter, one would have to
define the function or provide a forward declared version
2016-12-18 01:11:14 -08:00
practicalswift
38be6125e5 [gardening] C++ gardening: Terminate namespaces, fix argument names, ...
Changes:
* Terminate all namespaces with the correct closing comment.
* Make sure argument names in comments match the corresponding parameter name.
* Remove redundant get() calls on smart pointers.
* Prefer using "override" or "final" instead of "virtual". Remove "virtual" where appropriate.
2016-12-17 00:32:42 +01:00