Skip to content

Commit 0293324

Browse files
dbrattliclaude
andcommitted
Rename quotation module to "quotation" across all targets
Use "quotation" as the canonical module name: - Python: quotation.py (renamed from fable_quotation.py) - Beam: fable_quotation.erl (fable_ prefix added by getLibPath) - JS (#4474): Quotation.ts (natural mapping) Revert the Beam getLibPath workaround as it's no longer needed. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 90545bf commit 0293324

6 files changed

Lines changed: 47 additions & 62 deletions

File tree

src/Fable.Transforms/Beam/Replacements.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5560,7 +5560,7 @@ let tryCall
55605560
| _ -> None
55615561
| "System.Text.StringBuilder" -> bclType com ctx r t info thisArg args
55625562
// F# Quotations
5563-
| typeName -> Quotations.tryQuotationCall "fableQuotation" com ctx r t info thisArg args typeName
5563+
| typeName -> Quotations.tryQuotationCall "quotation" com ctx r t info thisArg args typeName
55645564

55655565
let tryBaseConstructor
55665566
(_com: ICompiler)

src/Fable.Transforms/Python/Replacements.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4156,7 +4156,7 @@ let tryCall (com: ICompiler) (ctx: Context) r t (info: CallInfo) (thisArg: Expr
41564156
| c -> Helper.LibCall(com, "Reflection", "name", t, [ c ], ?loc = r) |> Some
41574157
| _ -> None
41584158
// F# Quotations
4159-
| typeName -> Quotations.tryQuotationCall "fableQuotation" com ctx r t info thisArg args typeName
4159+
| typeName -> Quotations.tryQuotationCall "quotation" com ctx r t info thisArg args typeName
41604160

41614161
let tryBaseConstructor com ctx (ent: EntityRef) (argTypes: Lazy<Type list>) genArgs args =
41624162
match ent.FullName with

src/Fable.Transforms/QuotationEmitter.fs

Lines changed: 41 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ open Replacements.Util
99
/// Emits a Fable expression that, when compiled, produces runtime calls
1010
/// to construct a quotation AST. The input is the Fable.Expr captured
1111
/// inside a Quote node; the output is a Fable.Expr that calls the
12-
/// fable_quotation runtime library to build the AST at runtime.
12+
/// quotation runtime library to build the AST at runtime.
1313
let rec emitQuotedExpr (com: Compiler) (expr: Expr) : Expr =
1414
match expr with
1515
| Value(kind, r) -> emitQuotedValue com kind r
1616

1717
| IdentExpr ident ->
1818
// Reference to a variable already introduced by a lambda/let in the quotation.
19-
// Emit: fableQuotation.mkVar(Var)
19+
// Emit: quotation.mkVar(Var)
2020
// We need a var reference. Create a var and then wrap it.
2121
let varExpr =
2222
Helper.LibCall(
2323
com,
24-
"fableQuotation",
24+
"quotation",
2525
"mkQuotVar",
2626
Any,
2727
[
@@ -31,13 +31,13 @@ let rec emitQuotedExpr (com: Compiler) (expr: Expr) : Expr =
3131
]
3232
)
3333

34-
Helper.LibCall(com, "fableQuotation", "mkVar", Any, [ varExpr ])
34+
Helper.LibCall(com, "quotation", "mkVar", Any, [ varExpr ])
3535

3636
| Lambda(arg, body, _name) ->
3737
let varExpr =
3838
Helper.LibCall(
3939
com,
40-
"fableQuotation",
40+
"quotation",
4141
"mkQuotVar",
4242
Any,
4343
[
@@ -48,7 +48,7 @@ let rec emitQuotedExpr (com: Compiler) (expr: Expr) : Expr =
4848
)
4949

5050
let bodyExpr = emitQuotedExpr com body
51-
Helper.LibCall(com, "fableQuotation", "mkLambda", Any, [ varExpr; bodyExpr ])
51+
Helper.LibCall(com, "quotation", "mkLambda", Any, [ varExpr; bodyExpr ])
5252

5353
| Delegate(args, body, _name, _tags) ->
5454
// Multi-arg delegate: nest as curried lambdas
@@ -59,7 +59,7 @@ let rec emitQuotedExpr (com: Compiler) (expr: Expr) : Expr =
5959
let varExpr =
6060
Helper.LibCall(
6161
com,
62-
"fableQuotation",
62+
"quotation",
6363
"mkQuotVar",
6464
Any,
6565
[
@@ -70,15 +70,15 @@ let rec emitQuotedExpr (com: Compiler) (expr: Expr) : Expr =
7070
)
7171

7272
let innerBody = nestLambdas rest body
73-
Helper.LibCall(com, "fableQuotation", "mkLambda", Any, [ varExpr; innerBody ])
73+
Helper.LibCall(com, "quotation", "mkLambda", Any, [ varExpr; innerBody ])
7474

7575
nestLambdas args body
7676

7777
| Let(ident, value, body) ->
7878
let varExpr =
7979
Helper.LibCall(
8080
com,
81-
"fableQuotation",
81+
"quotation",
8282
"mkQuotVar",
8383
Any,
8484
[
@@ -91,13 +91,13 @@ let rec emitQuotedExpr (com: Compiler) (expr: Expr) : Expr =
9191
let valueExpr = emitQuotedExpr com value
9292
let bodyExpr = emitQuotedExpr com body
9393

94-
Helper.LibCall(com, "fableQuotation", "mkLet", Any, [ varExpr; valueExpr; bodyExpr ])
94+
Helper.LibCall(com, "quotation", "mkLet", Any, [ varExpr; valueExpr; bodyExpr ])
9595

9696
| IfThenElse(guardExpr, thenExpr, elseExpr, _r) ->
9797
let guard = emitQuotedExpr com guardExpr
9898
let thenE = emitQuotedExpr com thenExpr
9999
let elseE = emitQuotedExpr com elseExpr
100-
Helper.LibCall(com, "fableQuotation", "mkIfThenElse", Any, [ guard; thenE; elseE ])
100+
Helper.LibCall(com, "quotation", "mkIfThenElse", Any, [ guard; thenE; elseE ])
101101

102102
| CurriedApply(applied, args, _typ, _r) ->
103103
// Emit nested applications: Application(Application(f, a1), a2)
@@ -107,7 +107,7 @@ let rec emitQuotedExpr (com: Compiler) (expr: Expr) : Expr =
107107
|> List.fold
108108
(fun acc arg ->
109109
let argExpr = emitQuotedExpr com arg
110-
Helper.LibCall(com, "fableQuotation", "mkApplication", Any, [ acc; argExpr ])
110+
Helper.LibCall(com, "quotation", "mkApplication", Any, [ acc; argExpr ])
111111
)
112112
appliedExpr
113113

@@ -126,7 +126,7 @@ let rec emitQuotedExpr (com: Compiler) (expr: Expr) : Expr =
126126

127127
let argExprs = info.Args |> List.map (emitQuotedExpr com) |> makeArray Any
128128

129-
Helper.LibCall(com, "fableQuotation", "mkCall", Any, [ instanceExpr; methodExpr; argExprs ])
129+
Helper.LibCall(com, "quotation", "mkCall", Any, [ instanceExpr; methodExpr; argExprs ])
130130

131131
| Sequential exprs ->
132132
match exprs with
@@ -135,7 +135,7 @@ let rec emitQuotedExpr (com: Compiler) (expr: Expr) : Expr =
135135
| first :: rest ->
136136
let restExpr = emitQuotedExpr com (Sequential rest)
137137
let firstExpr = emitQuotedExpr com first
138-
Helper.LibCall(com, "fableQuotation", "mkSequential", Any, [ firstExpr; restExpr ])
138+
Helper.LibCall(com, "quotation", "mkSequential", Any, [ firstExpr; restExpr ])
139139

140140
| Operation(kind, _tags, _typ, _r) ->
141141
// Represent operations as calls to the operator method
@@ -187,21 +187,21 @@ let rec emitQuotedExpr (com: Compiler) (expr: Expr) : Expr =
187187

188188
let argExprs = args |> List.map (emitQuotedExpr com) |> makeArray Any
189189

190-
Helper.LibCall(com, "fableQuotation", "mkCall", Any, [ instanceExpr; methodExpr; argExprs ])
190+
Helper.LibCall(com, "quotation", "mkCall", Any, [ instanceExpr; methodExpr; argExprs ])
191191

192192
| Get(expr, kind, _typ, _r) ->
193193
let target = emitQuotedExpr com expr
194194

195195
match kind with
196-
| TupleIndex index -> Helper.LibCall(com, "fableQuotation", "mkTupleGet", Any, [ target; makeIntConst index ])
197-
| UnionTag -> Helper.LibCall(com, "fableQuotation", "mkUnionTag", Any, [ target ])
196+
| TupleIndex index -> Helper.LibCall(com, "quotation", "mkTupleGet", Any, [ target; makeIntConst index ])
197+
| UnionTag -> Helper.LibCall(com, "quotation", "mkUnionTag", Any, [ target ])
198198
| UnionField info ->
199-
Helper.LibCall(com, "fableQuotation", "mkUnionField", Any, [ target; makeIntConst info.FieldIndex ])
200-
| FieldGet info -> Helper.LibCall(com, "fableQuotation", "mkFieldGet", Any, [ target; makeStrConst info.Name ])
199+
Helper.LibCall(com, "quotation", "mkUnionField", Any, [ target; makeIntConst info.FieldIndex ])
200+
| FieldGet info -> Helper.LibCall(com, "quotation", "mkFieldGet", Any, [ target; makeStrConst info.Name ])
201201
| _ ->
202202
// ListHead, ListTail, OptionValue, ExprGet — fall through
203203
let msg = "Unsupported quotation Get kind"
204-
Helper.LibCall(com, "fableQuotation", "mkValue", Any, [ makeStrConst msg; makeStrConst "string" ])
204+
Helper.LibCall(com, "quotation", "mkValue", Any, [ makeStrConst msg; makeStrConst "string" ])
205205

206206
| Set(expr, kind, _typ, value, _r) ->
207207
let target = emitQuotedExpr com expr
@@ -210,12 +210,12 @@ let rec emitQuotedExpr (com: Compiler) (expr: Expr) : Expr =
210210
match kind with
211211
| ValueSet ->
212212
// Mutable variable set: expr is the ident, value is the new value
213-
Helper.LibCall(com, "fableQuotation", "mkVarSet", Any, [ target; valueExpr ])
213+
Helper.LibCall(com, "quotation", "mkVarSet", Any, [ target; valueExpr ])
214214
| FieldSet fieldName ->
215-
Helper.LibCall(com, "fableQuotation", "mkFieldSet", Any, [ target; makeStrConst fieldName; valueExpr ])
215+
Helper.LibCall(com, "quotation", "mkFieldSet", Any, [ target; makeStrConst fieldName; valueExpr ])
216216
| _ ->
217217
let msg = "Unsupported quotation Set kind"
218-
Helper.LibCall(com, "fableQuotation", "mkValue", Any, [ makeStrConst msg; makeStrConst "string" ])
218+
Helper.LibCall(com, "quotation", "mkValue", Any, [ makeStrConst msg; makeStrConst "string" ])
219219

220220
| TypeCast(innerExpr, _typ) ->
221221
// Coerce/cast: just emit the inner expression for now
@@ -228,48 +228,47 @@ let rec emitQuotedExpr (com: Compiler) (expr: Expr) : Expr =
228228
| [ ([], body) ] -> emitQuotedExpr com body
229229
| _ ->
230230
let msg = "Unsupported quotation node: DecisionTree"
231-
Helper.LibCall(com, "fableQuotation", "mkValue", Any, [ makeStrConst msg; makeStrConst "string" ])
231+
Helper.LibCall(com, "quotation", "mkValue", Any, [ makeStrConst msg; makeStrConst "string" ])
232232

233233
| DecisionTreeSuccess(idx, boundValues, _typ) ->
234234
match boundValues with
235235
| [] -> emitQuotedExpr com (Value(UnitConstant, None))
236236
| [ single ] -> emitQuotedExpr com single
237237
| _ ->
238238
let msg = "Unsupported quotation node: DecisionTreeSuccess"
239-
Helper.LibCall(com, "fableQuotation", "mkValue", Any, [ makeStrConst msg; makeStrConst "string" ])
239+
Helper.LibCall(com, "quotation", "mkValue", Any, [ makeStrConst msg; makeStrConst "string" ])
240240

241241
| _ ->
242242
// Unsupported node: emit an error value
243243
let msg = $"Unsupported quotation node: %A{expr.GetType().Name}"
244244

245-
Helper.LibCall(com, "fableQuotation", "mkValue", Any, [ makeStrConst msg; makeStrConst "string" ])
245+
Helper.LibCall(com, "quotation", "mkValue", Any, [ makeStrConst msg; makeStrConst "string" ])
246246

247247
and private emitQuotedValue (com: Compiler) (kind: ValueKind) (_r: SourceLocation option) : Expr =
248248
match kind with
249-
| BoolConstant b -> Helper.LibCall(com, "fableQuotation", "mkValue", Any, [ makeBoolConst b; makeStrConst "bool" ])
249+
| BoolConstant b -> Helper.LibCall(com, "quotation", "mkValue", Any, [ makeBoolConst b; makeStrConst "bool" ])
250250

251251
| NumberConstant(NumberValue.Int32 i, _) ->
252-
Helper.LibCall(com, "fableQuotation", "mkValue", Any, [ makeIntConst i; makeStrConst "int32" ])
252+
Helper.LibCall(com, "quotation", "mkValue", Any, [ makeIntConst i; makeStrConst "int32" ])
253253

254254
| NumberConstant(NumberValue.Float64 f, _) ->
255255
let floatExpr = Value(NumberConstant(NumberValue.Float64 f, NumberInfo.Empty), None)
256-
Helper.LibCall(com, "fableQuotation", "mkValue", Any, [ floatExpr; makeStrConst "float64" ])
256+
Helper.LibCall(com, "quotation", "mkValue", Any, [ floatExpr; makeStrConst "float64" ])
257257

258-
| StringConstant s ->
259-
Helper.LibCall(com, "fableQuotation", "mkValue", Any, [ makeStrConst s; makeStrConst "string" ])
258+
| StringConstant s -> Helper.LibCall(com, "quotation", "mkValue", Any, [ makeStrConst s; makeStrConst "string" ])
260259

261260
| UnitConstant ->
262-
Helper.LibCall(com, "fableQuotation", "mkValue", Any, [ Value(UnitConstant, None); makeStrConst "unit" ])
261+
Helper.LibCall(com, "quotation", "mkValue", Any, [ Value(UnitConstant, None); makeStrConst "unit" ])
263262

264-
| Null _ -> Helper.LibCall(com, "fableQuotation", "mkValue", Any, [ Value(Null Any, None); makeStrConst "null" ])
263+
| Null _ -> Helper.LibCall(com, "quotation", "mkValue", Any, [ Value(Null Any, None); makeStrConst "null" ])
265264

266265
| CharConstant c ->
267-
Helper.LibCall(com, "fableQuotation", "mkValue", Any, [ Value(CharConstant c, None); makeStrConst "char" ])
266+
Helper.LibCall(com, "quotation", "mkValue", Any, [ Value(CharConstant c, None); makeStrConst "char" ])
268267

269268
| NewTuple(values, _isStruct) ->
270269
let emittedValues = values |> List.map (emitQuotedExpr com) |> makeArray Any
271270

272-
Helper.LibCall(com, "fableQuotation", "mkNewTuple", Any, [ emittedValues ])
271+
Helper.LibCall(com, "quotation", "mkNewTuple", Any, [ emittedValues ])
273272

274273
| NewUnion(values, tag, entRef, _genArgs) ->
275274
let entName =
@@ -279,13 +278,7 @@ and private emitQuotedValue (com: Compiler) (kind: ValueKind) (_r: SourceLocatio
279278

280279
let emittedValues = values |> List.map (emitQuotedExpr com) |> makeArray Any
281280

282-
Helper.LibCall(
283-
com,
284-
"fableQuotation",
285-
"mkNewUnion",
286-
Any,
287-
[ makeStrConst entName; makeIntConst tag; emittedValues ]
288-
)
281+
Helper.LibCall(com, "quotation", "mkNewUnion", Any, [ makeStrConst entName; makeIntConst tag; emittedValues ])
289282

290283
| NewRecord(values, entRef, _genArgs) ->
291284
let fieldNames =
@@ -295,28 +288,27 @@ and private emitQuotedValue (com: Compiler) (kind: ValueKind) (_r: SourceLocatio
295288

296289
let emittedValues = values |> List.map (emitQuotedExpr com) |> makeArray Any
297290

298-
Helper.LibCall(com, "fableQuotation", "mkNewRecord", Any, [ fieldNames; emittedValues ])
291+
Helper.LibCall(com, "quotation", "mkNewRecord", Any, [ fieldNames; emittedValues ])
299292

300293
| NewOption(value, _typ, _isStruct) ->
301294
match value with
302295
| Some v ->
303296
let emitted = emitQuotedExpr com v
304-
Helper.LibCall(com, "fableQuotation", "mkValue", Any, [ emitted; makeStrConst "option" ])
305-
| None ->
306-
Helper.LibCall(com, "fableQuotation", "mkValue", Any, [ Value(Null Any, None); makeStrConst "option" ])
297+
Helper.LibCall(com, "quotation", "mkValue", Any, [ emitted; makeStrConst "option" ])
298+
| None -> Helper.LibCall(com, "quotation", "mkValue", Any, [ Value(Null Any, None); makeStrConst "option" ])
307299

308300
| NewList(headAndTail, _typ) ->
309301
match headAndTail with
310302
| Some(head, tail) ->
311303
let headExpr = emitQuotedExpr com head
312304
let tailExpr = emitQuotedExpr com tail
313-
Helper.LibCall(com, "fableQuotation", "mkNewList", Any, [ headExpr; tailExpr ])
314-
| None -> Helper.LibCall(com, "fableQuotation", "mkValue", Any, [ Value(Null Any, None); makeStrConst "list" ])
305+
Helper.LibCall(com, "quotation", "mkNewList", Any, [ headExpr; tailExpr ])
306+
| None -> Helper.LibCall(com, "quotation", "mkValue", Any, [ Value(Null Any, None); makeStrConst "list" ])
315307

316308
| _ ->
317309
// Fallback for other value kinds
318310
let msg = "Unsupported quotation value"
319-
Helper.LibCall(com, "fableQuotation", "mkValue", Any, [ makeStrConst msg; makeStrConst "string" ])
311+
Helper.LibCall(com, "quotation", "mkValue", Any, [ makeStrConst msg; makeStrConst "string" ])
320312

321313
and private typeToString (t: Type) : string =
322314
match t with

src/Fable.Transforms/Replacements.Util.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,8 +1447,8 @@ module AnonRecords =
14471447
| _ -> Ok() // TODO: Error instead if we cannot check the interface?
14481448

14491449
/// Shared quotation replacement functions for all targets.
1450-
/// Each target calls these with its own library module name (e.g., "fableQuotation" for Python/Beam, "Quotation" for JS).
1451-
/// Python and Beam auto-convert camelCase to snake_case in imports.
1450+
/// Each target calls these with its own library module name (e.g., "quotation" for Python/Beam, "Quotation" for JS).
1451+
/// Python converts to snake_case (quotation.py). Beam adds fable_ prefix (fable_quotation.erl).
14521452
module Quotations =
14531453

14541454
// F# Quotation: FSharpExpr static methods (e.g. Expr.Value, Expr.Lambda, etc.)

src/Fable.Transforms/Transforms.Util.fs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,15 +1194,8 @@ module AST =
11941194
// Fable-compiled .fs module — use name as-is (no fable_ prefix)
11951195
moduleName
11961196
else
1197-
// Apply snake_case first, then add fable_ prefix only if not already present
1198-
// e.g., "fableQuotation" -> "fable_quotation" (already has fable_ prefix after snake_case)
1199-
// e.g., "Option" -> "option" -> "fable_option"
1200-
let snaked = moduleName |> Naming.applyCaseRule Fable.Core.CaseRules.SnakeCase
1201-
1202-
if snaked.StartsWith("fable_", System.StringComparison.Ordinal) then
1203-
snaked
1204-
else
1205-
"fable_" + snaked
1197+
// JS fallback module name (e.g., "Option" -> "fable_option")
1198+
"fable_" + (moduleName |> Naming.applyCaseRule Fable.Core.CaseRules.SnakeCase)
12061199

12071200
com.LibraryDir + "/" + beamModuleName + ".erl"
12081201

File renamed without changes.

0 commit comments

Comments
 (0)