Skip to content

Commit 82ce107

Browse files
authored
s/dsl/rewriter/ (sorbet#2064)
* mv dsl rewriter * mv ./test/testdata/dsl ./test/testdata/rewriter * mv rewriter/dsl.h rewriter/rewriter.h * mv rewriter/dsl.cc rewriter/rewriter.cc * mv core/errors/dsl.h core/errors/rewriter.h * replace "dsl {" "rewriter {" * replace "dsl/" "rewriter/" * replace "//dsl" "//rewriter" * replace " = "dsl"" " = "rewriter"" * replace "DSLSynthesized" "RewriterSynthesized" * replace ""dsl"sv" ""rewriter"sv" * replace "dsl::" "rewriter::" * replace ""dsl-tree"" ""rewrite-tree"" * replace "skip-dsl-pass" "skip-rewriter-pass" * replace "sorbet::dsl" "sorbet::rewriter" * replace ""dsl-tree-raw"" ""rewrite-tree-raw"" * replace "dsl.h" "rewriter.h" * replace "Phase::DSL" "Phase::REWRITER" * replace ""dsl"" ""rewriter"" * replace "DSLTree" "RewriterTree" * replace "SORBET_DSL" "SORBET_REWRITER" * replace "errors::DSL" "errors::rewriter" * replace "class DSL final" "class Rewriter final" * replace "class DSL;" "class Rewriter;" * replace "DSL::run" "Rewriter::run" * replace "DSL_SYNTHESIZED" "REWRITER_SYNTHESIZED" * replace "skipDSLPasses" "skipRewriterPasses" * replace "SRUBY_DSL" "SORBET_REWRITER" * replace "DSL()" "Rewriter()" * replace "DSL pass" "Rewriter pass" * replace "DSL," "REWRITER," * replace "runDSL" "runRewriter" * replace "DSL synthesized" "Rewriter synthesized" * replace "replaceDSL" "run" * replace "patchDSL" "run" * replace "handleNamerDSL" "handleNamerRewriter" * replace "// DSL" "// Rewriter" * replace "dslsInlined" "rewriten" * replace "rewriter/dsl.cc" "rewriter/rewriter.cc" * replace "dsl pass" "Rewriter pass" * replace "dsl-tree" "rewrite-tree" * replace "#dsl" "#rewriter" * replace "\[DSL\]" "[Rewriter]" * replace " dsl " " rewriter " * replace "dsl.cc" "rewriter.cc" * replace "flags = dsl" "flags = rewriter" * replace "//rewriter:dsl" "//rewriter" * replace " DSL =" " rewriten =" * replace "(DSL)" "(rewriten)" * replace "!DSL)" "!rewriten)" * replace "## DSL" "## Rewriter" * replace "cache-rewriter" "cache-dsl" * replace "\[dsl\]" "\[rewriter]" * replace "dslUnwound" "rewriten" * replace "DSLReplacer" "Rewriterer" * replace "dslReplacer" "rewriter" * record * format * tools/scripts/generate_compdb_targets.sh * for i in `find . -name "*.dsl-tree-raw*"`; do mv $i ${i%dsl-tree-raw.exp}rewrite-tree-raw.exp; done * for i in `find . -name "*.dsl-tree*"`; do mv $i ${i%dsl-tree.exp}rewrite-tree.exp; done * record
1 parent 4e6a768 commit 82ce107

File tree

212 files changed

+12055
-883
lines changed

Some content is hidden

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

212 files changed

+12055
-883
lines changed

ast/Helpers.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ bool definesBehavior(const unique_ptr<ast::Expression> &expr) {
4040
definesBehavior(seq->expr);
4141
},
4242

43-
// Ignore code synthesized by DSL pass.
44-
[&](ast::Send *send) { result = !send->isDSLSynthesized(); },
45-
[&](ast::MethodDef *methodDef) { result = !methodDef->isDSLSynthesized(); },
43+
// Ignore code synthesized by Rewriter pass.
44+
[&](ast::Send *send) { result = !send->isRewriterSynthesized(); },
45+
[&](ast::MethodDef *methodDef) { result = !methodDef->isRewriterSynthesized(); },
4646

4747
[&](ast::Expression *klass) { result = true; });
4848
return result;

ast/Helpers.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ class MK {
296296
auto sig = Send0(loc, Constant(loc, core::Symbols::T_Sig_WithoutRuntime()), core::Names::sig());
297297
auto sigSend = ast::cast_tree<ast::Send>(sig.get());
298298
sigSend->block = Block0(loc, std::move(returns));
299-
sigSend->flags |= ast::Send::DSL_SYNTHESIZED;
299+
sigSend->flags |= ast::Send::REWRITER_SYNTHESIZED;
300300
return sig;
301301
}
302302

@@ -306,7 +306,7 @@ class MK {
306306
auto sig = Send0(loc, Constant(loc, core::Symbols::T_Sig_WithoutRuntime()), core::Names::sig());
307307
auto sigSend = ast::cast_tree<ast::Send>(sig.get());
308308
sigSend->block = Block0(loc, std::move(void_));
309-
sigSend->flags |= ast::Send::DSL_SYNTHESIZED;
309+
sigSend->flags |= ast::Send::REWRITER_SYNTHESIZED;
310310
return sig;
311311
}
312312

@@ -315,7 +315,7 @@ class MK {
315315
auto sig = Send0(loc, Constant(loc, core::Symbols::T_Sig_WithoutRuntime()), core::Names::sig());
316316
auto sigSend = ast::cast_tree<ast::Send>(sig.get());
317317
sigSend->block = Block0(loc, std::move(returns));
318-
sigSend->flags |= ast::Send::DSL_SYNTHESIZED;
318+
sigSend->flags |= ast::Send::REWRITER_SYNTHESIZED;
319319
return sig;
320320
}
321321

ast/Trees.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ string MethodDef::showRaw(const core::GlobalState &gs, int tabs) {
453453
buf << "flags =";
454454
const pair<int, string_view> flags[] = {
455455
{SelfMethod, "self"sv},
456-
{DSLSynthesized, "dsl"sv},
456+
{RewriterSynthesized, "rewriter"sv},
457457
};
458458
for (auto &ent : flags) {
459459
if ((this->flags & ent.first) != 0) {

ast/Trees.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class MethodDef final : public Declaration {
149149

150150
enum Flags {
151151
SelfMethod = 1,
152-
DSLSynthesized = 2,
152+
RewriterSynthesized = 2,
153153
};
154154

155155
MethodDef(core::Loc loc, core::Loc declLoc, core::SymbolRef symbol, core::NameRef name, ARGS_store args,
@@ -163,8 +163,8 @@ class MethodDef final : public Declaration {
163163
return (flags & SelfMethod) != 0;
164164
}
165165

166-
bool isDSLSynthesized() const {
167-
return (flags & DSLSynthesized) != 0;
166+
bool isRewriterSynthesized() const {
167+
return (flags & RewriterSynthesized) != 0;
168168
}
169169

170170
private:
@@ -461,7 +461,7 @@ class Send final : public Expression {
461461
core::NameRef fun;
462462

463463
static const int PRIVATE_OK = 1 << 0;
464-
static const int DSL_SYNTHESIZED = 1 << 1;
464+
static const int REWRITER_SYNTHESIZED = 1 << 1;
465465
u4 flags;
466466

467467
std::unique_ptr<Expression> recv;
@@ -478,8 +478,8 @@ class Send final : public Expression {
478478
virtual std::string nodeName();
479479
virtual std::unique_ptr<Expression> _deepCopy(const Expression *avoid, bool root = false) const;
480480

481-
bool isDSLSynthesized() const {
482-
return (flags & DSL_SYNTHESIZED) != 0;
481+
bool isRewriterSynthesized() const {
482+
return (flags & REWRITER_SYNTHESIZED) != 0;
483483
}
484484

485485
bool isPrivateOk() const {

core/GlobalState.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class GlobalState final {
169169
bool ensureCleanStrings = false;
170170

171171
// So we can know whether we're running in autogen mode.
172-
// Right now this is only used to turn certain DSL passes on or off.
172+
// Right now this is only used to turn certain Rewriter passes on or off.
173173
// Think very hard before looking at this value in namer / resolver!
174174
// (hint: probably you want to find an alternate solution)
175175
bool runningUnderAutogen = false;

core/Symbols.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ class Symbol final {
6464

6565
// --- Applies to all types of Symbols ---
6666

67-
// Synthesized by C++ code in a DSL pass
68-
static constexpr u4 DSL_SYNTHESIZED = 0x0000'0001;
67+
// Synthesized by C++ code in a Rewriter pass
68+
static constexpr u4 REWRITER_SYNTHESIZED = 0x0000'0001;
6969

7070
// --- For our current symbol type, what flags does it have?
7171

@@ -479,11 +479,11 @@ class Symbol final {
479479
return isStaticField() && (flags & Symbol::Flags::STATIC_FIELD_TYPE_ALIAS) != 0;
480480
}
481481

482-
inline void setDSLSynthesized() {
483-
flags |= Symbol::Flags::DSL_SYNTHESIZED;
482+
inline void setRewriterSynthesized() {
483+
flags |= Symbol::Flags::REWRITER_SYNTHESIZED;
484484
}
485-
inline bool isDSLSynthesized() const {
486-
return (flags & Symbol::Flags::DSL_SYNTHESIZED) != 0;
485+
inline bool isRewriterSynthesized() const {
486+
return (flags & Symbol::Flags::REWRITER_SYNTHESIZED) != 0;
487487
}
488488

489489
SymbolRef findMember(const GlobalState &gs, NameRef name) const;

core/errors/dsl.h core/errors/rewriter.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
#define SORBET_CORE_ERRORS_DSL_H
33
#include "core/Error.h"
44

5-
namespace sorbet::core::errors::DSL {
5+
namespace sorbet::core::errors::rewriter {
66
constexpr ErrorClass BadAttrArg{3501, StrictLevel::True};
77
constexpr ErrorClass BadWrapInstance{3502, StrictLevel::True};
88
constexpr ErrorClass PrivateMethodMismatch{3503, StrictLevel::False};
99
constexpr ErrorClass BadAttrType{3504, StrictLevel::True};
1010
constexpr ErrorClass BadModuleFunction{3505, StrictLevel::True};
1111
constexpr ErrorClass OpusEnumOutsideEnumsDo{3506, StrictLevel::False};
1212
constexpr ErrorClass OpusEnumConstNotEnumValue{3506, StrictLevel::False};
13-
} // namespace sorbet::core::errors::DSL
13+
} // namespace sorbet::core::errors::rewriter
1414
#endif

definition_validator/validator.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -314,23 +314,23 @@ void validateOverriding(const core::Context ctx, core::SymbolRef method) {
314314
auto isRBI = absl::c_any_of(method.data(ctx)->locs(), [&](auto &loc) { return loc.file().data(ctx).isRBI(); });
315315
if (!method.data(ctx)->isOverride() && method.data(ctx)->hasSig() &&
316316
overridenMethod.data(ctx)->isOverridable() && !anyIsInterface && overridenMethod.data(ctx)->hasSig() &&
317-
!method.data(ctx)->isDSLSynthesized() && !isRBI) {
317+
!method.data(ctx)->isRewriterSynthesized() && !isRBI) {
318318
if (auto e = ctx.state.beginError(method.data(ctx)->loc(), core::errors::Resolver::UndeclaredOverride)) {
319319
e.setHeader("Method `{}` overrides an overridable method `{}` but is not declared with `{}`",
320320
method.data(ctx)->show(ctx), overridenMethod.data(ctx)->show(ctx), "override.");
321321
e.addErrorLine(overridenMethod.data(ctx)->loc(), "defined here");
322322
}
323323
}
324324
if (!method.data(ctx)->isOverride() && method.data(ctx)->hasSig() && overridenMethod.data(ctx)->isAbstract() &&
325-
overridenMethod.data(ctx)->hasSig() && !method.data(ctx)->isDSLSynthesized() && !isRBI) {
325+
overridenMethod.data(ctx)->hasSig() && !method.data(ctx)->isRewriterSynthesized() && !isRBI) {
326326
if (auto e = ctx.state.beginError(method.data(ctx)->loc(), core::errors::Resolver::UndeclaredOverride)) {
327327
e.setHeader("Method `{}` implements an abstract method `{}` but is not declared with `{}`",
328328
method.data(ctx)->show(ctx), overridenMethod.data(ctx)->show(ctx), "override.");
329329
e.addErrorLine(overridenMethod.data(ctx)->loc(), "defined here");
330330
}
331331
}
332332
if ((overridenMethod.data(ctx)->isAbstract() || overridenMethod.data(ctx)->isOverridable()) &&
333-
!method.data(ctx)->isIncompatibleOverride() && !isRBI && !method.data(ctx)->isDSLSynthesized()) {
333+
!method.data(ctx)->isIncompatibleOverride() && !isRBI && !method.data(ctx)->isRewriterSynthesized()) {
334334
if (overridenMethod.data(ctx)->isFinalMethod()) {
335335
if (auto e = ctx.state.beginError(method.data(ctx)->loc(), core::errors::Resolver::OverridesFinal)) {
336336
e.setHeader("Method overrides a final method `{}`", overridenMethod.data(ctx)->show(ctx));

docs/internals.md

+13-13
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ unfinished or confusing section!
2020
- [Phases](#phases)
2121
- [Parser](#parser)
2222
- [Desugar](#desugar)
23-
- [DSL](#dsl)
23+
- [Rewriter](#rewriter)
2424
- [LocalVars](#localvars)
2525
- [Namer](#namer)
2626
- [Resolver](#resolver)
@@ -120,8 +120,8 @@ another or make modifications within the IR they were given.
120120
| 1 | [Parser], `-p parse-tree` | | |
121121
| | | [`parser::Node`] | |
122122
| 2 | [Desugar], `-p desugar-tree` | | |
123-
| 3 | | [`ast::Expression`] | [DSL] |
124-
| 4 | | [`ast::Expression`] | [LocalVars], `-p dsl-tree` |
123+
| 3 | | [`ast::Expression`] | [Rewriter] |
124+
| 4 | | [`ast::Expression`] | [LocalVars], `-p rewrite-tree` |
125125
| 5 | | [`ast::Expression`] | [Namer], `-p name-tree` (*) |
126126
| 6 | | [`ast::Expression`] | [Resolver], `-p resolve-tree` (*) |
127127
| 6 | | [`ast::Expression`] | [Flattener], `-p flatten-tree` |
@@ -161,7 +161,7 @@ The header itself is generated using [parser/tools/generate_ast.cc].
161161

162162
In general, the IR the parser generates is intended to model Ruby very
163163
granularly, but is frequently redundant for the purpose of typechecking. We use
164-
the Desugar and DSL passes to simplify the IR before typechecking.
164+
the Desugar and Rewriter passes to simplify the IR before typechecking.
165165

166166

167167
### Desugar
@@ -188,9 +188,9 @@ If you pass the `-p desugar-tree` or `-p desugar-tree-raw` option to `sorbet`,
188188
you can see what a Ruby program looks like after being desugared.
189189

190190

191-
### DSL
191+
### Rewriter
192192

193-
The DSL pass is sort of like a domain-specific desugar pass. It takes
193+
The Rewriter pass is sort of like a domain-specific desugar pass. It takes
194194
[`ast::Expression`]s and rewrites specific Ruby DSLs and metaprogramming into
195195
code that Sorbet can analyze. DSL in this context can have a broad meaning. Some
196196
examples of DSLs that are rewritten by this pass:
@@ -201,16 +201,16 @@ examples of DSLs that are rewritten by this pass:
201201

202202
- `Chalk::ODM`'s `prop` definitions are written similarly to `attr_reader`
203203

204-
The core dsl pass lives in [dsl/dsl.cc].
205-
Each DSL pass lives in its own file in the [dsl/] folder.
204+
The core Rewriter pass lives in [rewriter/rewriter.cc].
205+
Each Rewriter pass lives in its own file in the [rewriter/] folder.
206206

207207
In the future, we anticipate rewriting the DSL phase with a plugin architecture.
208208
This will allow for a wider audience of Rubyists to teach Sorbet about DSLs
209209
they've written.
210210

211-
We artificially limit what code we call from DSL passes. Sometimes it would be
211+
We artificially limit what code we call from Rewriter passes. Sometimes it would be
212212
convenient to call into other phases of Sorbet, but instead we've reimplemented
213-
functionality in the DSL pass. This keeps the surface area of the API we'll have
213+
functionality in the Rewriter pass. This keeps the surface area of the API we'll have
214214
to present to plugins in the future small.
215215

216216

@@ -627,7 +627,7 @@ See [core/Symbols.h] and [core/SymbolRef.h] for more information.
627627
<!-- Phase descriptions -->
628628
[parser]: #parser
629629
[desugar]: #desugar
630-
[dsl]: #dsl
630+
[rewriter]: #rewriter
631631
[localvars]: #localvars
632632
[namer]: #namer
633633
[resolver]: #resolver
@@ -647,8 +647,8 @@ See [core/Symbols.h] and [core/SymbolRef.h] for more information.
647647
<!-- Files -->
648648
[parser/tools/generate_ast.cc]: ../parser/tools/generate_ast.cc
649649
[ast/desugar/Desugar.cc]: ../ast/desugar/Desugar.cc
650-
[dsl/dsl.cc]: ../dsl/dsl.cc
651-
[dsl/]: ../dsl/
650+
[rewriter/rewriter.cc]: ../rewriter/rewriter.cc
651+
[rewriter/]: ../rewriter/
652652
[namer/namer.cc]: ../namer/namer.cc
653653
[resolver/resolver.cc]: ../resolver/resolver.cc
654654
[cfg/CFG.h]: ../cfg/CFG.h

docs/pipeline.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ where what the phases of Sorbet actually do are documented.
2929
│ │ ast::Expression │ │ │ ast::Expression │ │ │ ast::Expression │ │
3030
│ └─────────────────┘ │ └─────────────────┘ │ └─────────────────┘ │
3131
│ │ │ │ │ │ │
32-
│ │ dsl │ │ dsl │ │ dsl
32+
│ │ rewriter │ │ rewriter │ │ rewriter
3333
│ ▼ │ ▼ │ ▼ │
3434
│ ┌─────────────────┐ │ ┌─────────────────┐ │ ┌─────────────────┐ │
3535
│ │ ast::Expression │ │ │ ast::Expression │ │ │ ast::Expression │ │

dsl/Regexp.h

-26
This file was deleted.

dsl/TypeMembers.h

-19
This file was deleted.

infer/BUILD

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ cc_test(
4141
"infer",
4242
"//ast/desugar",
4343
"//cfg",
44-
"//dsl",
4544
"//flattener",
4645
"//local_vars",
4746
"//namer",
4847
"//resolver",
48+
"//rewriter",
4949
"@com_google_googletest//:gtest",
5050
"@com_google_googletest//:gtest_main",
5151
],

infer/SigSuggestion.cc

+4-3
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,8 @@ bool childNeedsOverride(core::Context ctx, core::SymbolRef childSymbol, core::Sy
299299
!parentSymbol.data(ctx)->loc().file().data(ctx).isRBI() &&
300300
// that isn't the constructor...
301301
childSymbol.data(ctx)->name != core::Names::initialize() &&
302-
// and wasn't DSL synthesized (beause we can't change DSL'd sigs).
303-
!parentSymbol.data(ctx)->isDSLSynthesized() &&
302+
// and wasn't Rewriter synthesized (beause we can't change DSL'd sigs).
303+
!parentSymbol.data(ctx)->isRewriterSynthesized() &&
304304
// It has a sig...
305305
parentSymbol.data(ctx)->resultType != nullptr &&
306306
// that is either overridable...
@@ -370,7 +370,8 @@ bool SigSuggestion::maybeSuggestSig(core::Context ctx, core::ErrorBuilder &e, un
370370
}
371371

372372
auto loc = methodSymbol.data(ctx)->loc();
373-
// Sometimes the methodSymbol we're looking at has been synthesized by a DSL pass, so no 'def' exists in the source
373+
// Sometimes the methodSymbol we're looking at has been synthesized by a Rewriter pass, so no 'def' exists in the
374+
// source
374375
if (loc.file().data(ctx).source().substr(loc.beginPos(), 3) != "def") {
375376
return false;
376377
}

infer/test/infer_test.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
#include "core/ErrorQueue.h"
88
#include "core/Names.h"
99
#include "core/Unfreeze.h"
10-
#include "dsl/dsl.h"
1110
#include "flattener/flatten.h"
1211
#include "infer/infer.h"
1312
#include "local_vars/local_vars.h"
1413
#include "namer/namer.h"
1514
#include "resolver/resolver.h"
15+
#include "rewriter/rewriter.h"
1616
#include "spdlog/spdlog.h"
1717
// has to come before the next one. This comment stops formatter from reordering them
1818
#include "spdlog/sinks/stdout_color_sinks.h"
@@ -49,7 +49,7 @@ void processSource(core::GlobalState &cb, string str) {
4949
sorbet::core::MutableContext ctx(cb, core::Symbols::root());
5050
auto fileId = ast->loc.file();
5151
auto tree = ast::ParsedFile{ast::desugar::node2Tree(ctx, move(ast)), fileId};
52-
tree.tree = dsl::DSL::run(ctx, move(tree.tree));
52+
tree.tree = rewriter::Rewriter::run(ctx, move(tree.tree));
5353
tree = local_vars::LocalVars::run(ctx, move(tree));
5454
vector<ast::ParsedFile> trees;
5555
trees.emplace_back(move(tree));

0 commit comments

Comments
 (0)