Skip to content

Commit 29c3993

Browse files
authored
refactor(compiler-base): move 'compiler_base' from 'KCLVM/kclvm' to 'KCLVM'. (#192)
move 'compiler_base' from 'KCLVM/kclvm' to 'KCLVM'. issue #115
1 parent 5431a04 commit 29c3993

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+7532
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[package]
2+
name = "rustc_data_structures"
3+
version = "0.0.0"
4+
edition = "2021"
5+
6+
[lib]
7+
doctest = false
8+
9+
[dependencies]
10+
arrayvec = { version = "0.7", default-features = false }
11+
ena = "0.14"
12+
indexmap = { version = "1.8.0", features = ["rustc-rayon"] }
13+
tracing = "0.1"
14+
jobserver_crate = { version = "0.1.13", package = "jobserver" }
15+
16+
cfg-if = "0.1.2"
17+
stable_deref_trait = "1.0.0"
18+
rayon = { version = "0.3.2", package = "rustc-rayon" }
19+
rayon-core = { version = "0.3.2", package = "rustc-rayon-core" }
20+
rustc-hash = "1.1.0"
21+
bitflags = "1.2.1"
22+
libc = "0.2"
23+
stacker = "0.1.14"
24+
tempfile = "3.2"
25+
26+
[dependencies.parking_lot]
27+
version = "0.12"
28+
29+
[target.'cfg(windows)'.dependencies]
30+
winapi = { version = "0.3", features = ["fileapi", "psapi", "winerror"] }
31+
32+
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
33+
memmap2 = "0.2.1"
Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
Short version for non-lawyers:
2+
3+
The Rust Project is dual-licensed under Apache 2.0 and MIT
4+
terms.
5+
6+
7+
Longer version:
8+
9+
Copyrights in the Rust project are retained by their contributors. No
10+
copyright assignment is required to contribute to the Rust project.
11+
12+
Some files include explicit copyright notices and/or license notices.
13+
For full authorship information, see the version control history or
14+
https://thanks.rust-lang.org
15+
16+
Except as otherwise noted (below and/or in individual files), Rust is
17+
licensed under the Apache License, Version 2.0 <LICENSE-APACHE> or
18+
<http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
19+
<LICENSE-MIT> or <http://opensource.org/licenses/MIT>, at your option.
20+
21+
22+
The Rust Project includes packages written by third parties.
23+
The following third party packages are included, and carry
24+
their own copyright notices and license terms:
25+
26+
* LLVM. Code for this package is found in src/llvm-project.
27+
28+
Copyright (c) 2003-2013 University of Illinois at
29+
Urbana-Champaign. All rights reserved.
30+
31+
Developed by:
32+
33+
LLVM Team
34+
35+
University of Illinois at Urbana-Champaign
36+
37+
http://llvm.org
38+
39+
Permission is hereby granted, free of charge, to any
40+
person obtaining a copy of this software and associated
41+
documentation files (the "Software"), to deal with the
42+
Software without restriction, including without
43+
limitation the rights to use, copy, modify, merge,
44+
publish, distribute, sublicense, and/or sell copies of
45+
the Software, and to permit persons to whom the Software
46+
is furnished to do so, subject to the following
47+
conditions:
48+
49+
* Redistributions of source code must retain the
50+
above copyright notice, this list of conditions
51+
and the following disclaimers.
52+
53+
* Redistributions in binary form must reproduce the
54+
above copyright notice, this list of conditions
55+
and the following disclaimers in the documentation
56+
and/or other materials provided with the
57+
distribution.
58+
59+
* Neither the names of the LLVM Team, University of
60+
Illinois at Urbana-Champaign, nor the names of its
61+
contributors may be used to endorse or promote
62+
products derived from this Software without
63+
specific prior written permission.
64+
65+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
66+
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
67+
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
68+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
69+
SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE
70+
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
71+
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
72+
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
73+
OTHER DEALINGS WITH THE SOFTWARE.
74+
75+
* Additional libraries included in LLVM carry separate
76+
BSD-compatible licenses. See src/llvm-project/llvm/LICENSE.TXT
77+
for details.
78+
79+
* compiler-rt, in src/compiler-rt is dual licensed under
80+
LLVM's license and MIT:
81+
82+
Copyright (c) 2009-2014 by the contributors listed in
83+
CREDITS.TXT
84+
85+
All rights reserved.
86+
87+
Developed by:
88+
89+
LLVM Team
90+
91+
University of Illinois at Urbana-Champaign
92+
93+
http://llvm.org
94+
95+
Permission is hereby granted, free of charge, to any
96+
person obtaining a copy of this software and associated
97+
documentation files (the "Software"), to deal with the
98+
Software without restriction, including without
99+
limitation the rights to use, copy, modify, merge,
100+
publish, distribute, sublicense, and/or sell copies of
101+
the Software, and to permit persons to whom the Software
102+
is furnished to do so, subject to the following
103+
conditions:
104+
105+
* Redistributions of source code must retain the
106+
above copyright notice, this list of conditions
107+
and the following disclaimers.
108+
109+
* Redistributions in binary form must reproduce the
110+
above copyright notice, this list of conditions
111+
and the following disclaimers in the documentation
112+
and/or other materials provided with the
113+
distribution.
114+
115+
* Neither the names of the LLVM Team, University of
116+
Illinois at Urbana-Champaign, nor the names of its
117+
contributors may be used to endorse or promote
118+
products derived from this Software without
119+
specific prior written permission.
120+
121+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
122+
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
123+
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
124+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
125+
SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE
126+
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
127+
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
128+
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
129+
OTHER DEALINGS WITH THE SOFTWARE.
130+
131+
========================================================
132+
133+
Copyright (c) 2009-2014 by the contributors listed in
134+
CREDITS.TXT
135+
136+
Permission is hereby granted, free of charge, to any
137+
person obtaining a copy of this software and associated
138+
documentation files (the "Software"), to deal in the
139+
Software without restriction, including without
140+
limitation the rights to use, copy, modify, merge,
141+
publish, distribute, sublicense, and/or sell copies of
142+
the Software, and to permit persons to whom the Software
143+
is furnished to do so, subject to the following
144+
conditions:
145+
146+
The above copyright notice and this permission notice
147+
shall be included in all copies or substantial portions
148+
of the Software.
149+
150+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
151+
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
152+
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
153+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
154+
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
155+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
156+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
157+
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
158+
DEALINGS IN THE SOFTWARE.
159+
160+
* Portions of the FFI code for interacting with the native ABI
161+
is derived from the Clay programming language, which carries
162+
the following license.
163+
164+
Copyright (C) 2008-2010 Tachyon Technologies.
165+
All rights reserved.
166+
167+
Redistribution and use in source and binary forms, with
168+
or without modification, are permitted provided that the
169+
following conditions are met:
170+
171+
1. Redistributions of source code must retain the above
172+
copyright notice, this list of conditions and the
173+
following disclaimer.
174+
175+
2. Redistributions in binary form must reproduce the
176+
above copyright notice, this list of conditions and
177+
the following disclaimer in the documentation and/or
178+
other materials provided with the distribution.
179+
180+
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR
181+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
182+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
183+
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
184+
DEVELOPERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
185+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
186+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
187+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
188+
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
189+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
190+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
191+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
192+
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
193+
OF SUCH DAMAGE.
194+
195+
* libbacktrace, under src/libbacktrace:
196+
197+
Copyright (C) 2012-2014 Free Software Foundation, Inc.
198+
Written by Ian Lance Taylor, Google.
199+
200+
Redistribution and use in source and binary forms, with
201+
or without modification, are permitted provided that the
202+
following conditions are met:
203+
204+
(1) Redistributions of source code must retain the
205+
above copyright notice, this list of conditions and
206+
the following disclaimer.
207+
208+
(2) Redistributions in binary form must reproduce
209+
the above copyright notice, this list of conditions
210+
and the following disclaimer in the documentation
211+
and/or other materials provided with the
212+
distribution.
213+
214+
(3) The name of the author may not be used to
215+
endorse or promote products derived from this
216+
software without specific prior written permission.
217+
218+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
219+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
220+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
221+
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
222+
NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
223+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
224+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
225+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
226+
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
227+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
228+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
229+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
230+
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
231+
OF SUCH DAMAGE. */
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use std::marker::PhantomData;
2+
use std::sync::atomic::{AtomicPtr, Ordering};
3+
4+
/// This is essentially an `AtomicPtr` but is guaranteed to always be valid
5+
pub struct AtomicRef<T: 'static>(AtomicPtr<T>, PhantomData<&'static T>);
6+
7+
impl<T: 'static> AtomicRef<T> {
8+
pub const fn new(initial: &'static T) -> AtomicRef<T> {
9+
AtomicRef(AtomicPtr::new(initial as *const T as *mut T), PhantomData)
10+
}
11+
12+
pub fn swap(&self, new: &'static T) -> &'static T {
13+
// We never allow storing anything but a `'static` reference so it's safe to
14+
// return it for the same.
15+
unsafe { &*self.0.swap(new as *const T as *mut T, Ordering::SeqCst) }
16+
}
17+
}
18+
19+
impl<T: 'static> std::ops::Deref for AtomicRef<T> {
20+
type Target = T;
21+
fn deref(&self) -> &Self::Target {
22+
// We never allow storing anything but a `'static` reference so it's safe to lend
23+
// it out for any amount of time.
24+
unsafe { &*self.0.load(Ordering::SeqCst) }
25+
}
26+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/// Converts unsigned integers into a string representation with some base.
2+
/// Bases up to and including 36 can be used for case-insensitive things.
3+
use std::str;
4+
5+
pub const MAX_BASE: usize = 64;
6+
pub const ALPHANUMERIC_ONLY: usize = 62;
7+
pub const CASE_INSENSITIVE: usize = 36;
8+
9+
const BASE_64: &[u8; MAX_BASE as usize] =
10+
b"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@$";
11+
12+
#[inline]
13+
pub fn push_str(mut n: u128, base: usize, output: &mut String) {
14+
debug_assert!(base >= 2 && base <= MAX_BASE);
15+
let mut s = [0u8; 128];
16+
let mut index = 0;
17+
18+
let base = base as u128;
19+
20+
loop {
21+
s[index] = BASE_64[(n % base) as usize];
22+
index += 1;
23+
n /= base;
24+
25+
if n == 0 {
26+
break;
27+
}
28+
}
29+
s[0..index].reverse();
30+
31+
output.push_str(str::from_utf8(&s[0..index]).unwrap());
32+
}
33+
34+
#[inline]
35+
pub fn encode(n: u128, base: usize) -> String {
36+
let mut s = String::new();
37+
push_str(n, base, &mut s);
38+
s
39+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/// "Signaling" trait used in impl trait to tag lifetimes that you may
2+
/// need to capture but don't really need for other reasons.
3+
/// Basically a workaround; see [this comment] for details.
4+
///
5+
/// [this comment]: https://github.com/rust-lang/rust/issues/34511#issuecomment-373423999
6+
pub trait Captures<'a> {}
7+
8+
impl<'a, T: ?Sized> Captures<'a> for T {}

0 commit comments

Comments
 (0)