mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-15 15:18:11 +00:00
Remove global_arena (#814)
With this, only main.cpp instantiates an arena. Maybe we'll want to split that up more later (e.g., so that the runtime interpreter uses its own arena), but given the intent to have type-checking update the AST, I thought this was a reasonable approach for now in order to avoid ownership complexities. Fixes #769
This commit is contained in:
1 parent
3610325c38
commit
90f04700e2
27 files changed
+568
-581
No files matched your search
@@ -29,26 +29,31 @@ static auto FakeSourceLoc(int line_num) -> SourceLocation {
|
||||
return SourceLocation("<test>", line_num);
|
||||
}
|
||||
|
||||
TEST(PatternTest, EmptyAsPattern) {
|
||||
class PatternTest : public ::testing::Test {
|
||||
protected:
|
||||
Arena arena;
|
||||
};
|
||||
|
||||
TEST_F(PatternTest, EmptyAsPattern) {
|
||||
ParenContents<Pattern> contents = {.elements = {},
|
||||
.has_trailing_comma = false};
|
||||
Ptr<const Pattern> pattern =
|
||||
PatternFromParenContents(FakeSourceLoc(1), contents);
|
||||
PatternFromParenContents(PtrTo(arena), FakeSourceLoc(1), contents);
|
||||
EXPECT_EQ(pattern->SourceLoc(), FakeSourceLoc(1));
|
||||
ASSERT_TRUE(isa<TuplePattern>(*pattern));
|
||||
EXPECT_THAT(cast<TuplePattern>(*pattern).Fields(), IsEmpty());
|
||||
}
|
||||
|
||||
TEST(PatternTest, EmptyAsTuplePattern) {
|
||||
TEST_F(PatternTest, EmptyAsTuplePattern) {
|
||||
ParenContents<Pattern> contents = {.elements = {},
|
||||
.has_trailing_comma = false};
|
||||
Ptr<const TuplePattern> tuple =
|
||||
TuplePatternFromParenContents(FakeSourceLoc(1), contents);
|
||||
TuplePatternFromParenContents(PtrTo(arena), FakeSourceLoc(1), contents);
|
||||
EXPECT_EQ(tuple->SourceLoc(), FakeSourceLoc(1));
|
||||
EXPECT_THAT(tuple->Fields(), IsEmpty());
|
||||
}
|
||||
|
||||
TEST(PatternTest, UnaryNoCommaAsPattern) {
|
||||
TEST_F(PatternTest, UnaryNoCommaAsPattern) {
|
||||
// Equivalent to a code fragment like
|
||||
// ```
|
||||
// (
|
||||
@@ -57,79 +62,79 @@ TEST(PatternTest, UnaryNoCommaAsPattern) {
|
||||
// ```
|
||||
ParenContents<Pattern> contents = {
|
||||
.elements = {{.name = std::nullopt,
|
||||
.term = global_arena->New<AutoPattern>(FakeSourceLoc(2))}},
|
||||
.term = arena.New<AutoPattern>(FakeSourceLoc(2))}},
|
||||
.has_trailing_comma = false};
|
||||
|
||||
Ptr<const Pattern> pattern =
|
||||
PatternFromParenContents(FakeSourceLoc(1), contents);
|
||||
PatternFromParenContents(PtrTo(arena), FakeSourceLoc(1), contents);
|
||||
EXPECT_EQ(pattern->SourceLoc(), FakeSourceLoc(2));
|
||||
ASSERT_TRUE(isa<AutoPattern>(*pattern));
|
||||
}
|
||||
|
||||
TEST(PatternTest, UnaryNoCommaAsTuplePattern) {
|
||||
TEST_F(PatternTest, UnaryNoCommaAsTuplePattern) {
|
||||
ParenContents<Pattern> contents = {
|
||||
.elements = {{.name = std::nullopt,
|
||||
.term = global_arena->New<AutoPattern>(FakeSourceLoc(2))}},
|
||||
.term = arena.New<AutoPattern>(FakeSourceLoc(2))}},
|
||||
.has_trailing_comma = false};
|
||||
|
||||
Ptr<const TuplePattern> tuple =
|
||||
TuplePatternFromParenContents(FakeSourceLoc(1), contents);
|
||||
TuplePatternFromParenContents(PtrTo(arena), FakeSourceLoc(1), contents);
|
||||
EXPECT_EQ(tuple->SourceLoc(), FakeSourceLoc(1));
|
||||
EXPECT_THAT(tuple->Fields(), ElementsAre(AutoFieldNamed("0")));
|
||||
}
|
||||
|
||||
TEST(PatternTest, UnaryWithCommaAsPattern) {
|
||||
TEST_F(PatternTest, UnaryWithCommaAsPattern) {
|
||||
ParenContents<Pattern> contents = {
|
||||
.elements = {{.name = std::nullopt,
|
||||
.term = global_arena->New<AutoPattern>(FakeSourceLoc(2))}},
|
||||
.term = arena.New<AutoPattern>(FakeSourceLoc(2))}},
|
||||
.has_trailing_comma = true};
|
||||
|
||||
Ptr<const Pattern> pattern =
|
||||
PatternFromParenContents(FakeSourceLoc(1), contents);
|
||||
PatternFromParenContents(PtrTo(arena), FakeSourceLoc(1), contents);
|
||||
EXPECT_EQ(pattern->SourceLoc(), FakeSourceLoc(1));
|
||||
ASSERT_TRUE(isa<TuplePattern>(*pattern));
|
||||
EXPECT_THAT(cast<TuplePattern>(*pattern).Fields(),
|
||||
ElementsAre(AutoFieldNamed("0")));
|
||||
}
|
||||
|
||||
TEST(PatternTest, UnaryWithCommaAsTuplePattern) {
|
||||
TEST_F(PatternTest, UnaryWithCommaAsTuplePattern) {
|
||||
ParenContents<Pattern> contents = {
|
||||
.elements = {{.name = std::nullopt,
|
||||
.term = global_arena->New<AutoPattern>(FakeSourceLoc(2))}},
|
||||
.term = arena.New<AutoPattern>(FakeSourceLoc(2))}},
|
||||
.has_trailing_comma = true};
|
||||
|
||||
Ptr<const TuplePattern> tuple =
|
||||
TuplePatternFromParenContents(FakeSourceLoc(1), contents);
|
||||
TuplePatternFromParenContents(PtrTo(arena), FakeSourceLoc(1), contents);
|
||||
EXPECT_EQ(tuple->SourceLoc(), FakeSourceLoc(1));
|
||||
EXPECT_THAT(tuple->Fields(), ElementsAre(AutoFieldNamed("0")));
|
||||
}
|
||||
|
||||
TEST(PatternTest, BinaryAsPattern) {
|
||||
TEST_F(PatternTest, BinaryAsPattern) {
|
||||
ParenContents<Pattern> contents = {
|
||||
.elements = {{.name = std::nullopt,
|
||||
.term = global_arena->New<AutoPattern>(FakeSourceLoc(2))},
|
||||
.term = arena.New<AutoPattern>(FakeSourceLoc(2))},
|
||||
{.name = std::nullopt,
|
||||
.term = global_arena->New<AutoPattern>(FakeSourceLoc(2))}},
|
||||
.term = arena.New<AutoPattern>(FakeSourceLoc(2))}},
|
||||
.has_trailing_comma = true};
|
||||
|
||||
Ptr<const Pattern> pattern =
|
||||
PatternFromParenContents(FakeSourceLoc(1), contents);
|
||||
PatternFromParenContents(PtrTo(arena), FakeSourceLoc(1), contents);
|
||||
EXPECT_EQ(pattern->SourceLoc(), FakeSourceLoc(1));
|
||||
ASSERT_TRUE(isa<TuplePattern>(*pattern));
|
||||
EXPECT_THAT(cast<TuplePattern>(*pattern).Fields(),
|
||||
ElementsAre(AutoFieldNamed("0"), AutoFieldNamed("1")));
|
||||
}
|
||||
|
||||
TEST(PatternTest, BinaryAsTuplePattern) {
|
||||
TEST_F(PatternTest, BinaryAsTuplePattern) {
|
||||
ParenContents<Pattern> contents = {
|
||||
.elements = {{.name = std::nullopt,
|
||||
.term = global_arena->New<AutoPattern>(FakeSourceLoc(2))},
|
||||
.term = arena.New<AutoPattern>(FakeSourceLoc(2))},
|
||||
{.name = std::nullopt,
|
||||
.term = global_arena->New<AutoPattern>(FakeSourceLoc(2))}},
|
||||
.term = arena.New<AutoPattern>(FakeSourceLoc(2))}},
|
||||
.has_trailing_comma = true};
|
||||
|
||||
Ptr<const TuplePattern> tuple =
|
||||
TuplePatternFromParenContents(FakeSourceLoc(1), contents);
|
||||
TuplePatternFromParenContents(PtrTo(arena), FakeSourceLoc(1), contents);
|
||||
EXPECT_EQ(tuple->SourceLoc(), FakeSourceLoc(1));
|
||||
EXPECT_THAT(tuple->Fields(),
|
||||
ElementsAre(AutoFieldNamed("0"), AutoFieldNamed("1")));
|
||||
|
||||
Reference in new issue
Block a user