Skip to content

Commit 90545bf

Browse files
dbrattliclaude
andcommitted
Use camelCase for all quotation library names in compiler
QuotationEmitter.fs and Beam Replacements now use camelCase module/function names (fableQuotation, mkQuotVar, mkVar, mkApplication, etc.). Python and Beam auto-convert to snake_case via getLibPath and sanitizeErlangName. Fix Beam getLibPath to handle camelCase fable-prefixed names correctly (fableQuotation -> fable_quotation, not fable_fable_quotation). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 371052e commit 90545bf

3 files changed

Lines changed: 55 additions & 52 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 "fable_quotation" com ctx r t info thisArg args typeName
5563+
| typeName -> Quotations.tryQuotationCall "fableQuotation" com ctx r t info thisArg args typeName
55645564

55655565
let tryBaseConstructor
55665566
(_com: ICompiler)

src/Fable.Transforms/QuotationEmitter.fs

Lines changed: 45 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ let rec emitQuotedExpr (com: Compiler) (expr: Expr) : Expr =
1616

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

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

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

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

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

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

7575
nestLambdas args body
7676

7777
| Let(ident, value, body) ->
7878
let varExpr =
7979
Helper.LibCall(
8080
com,
81-
"fable_quotation",
82-
"mk_var",
81+
"fableQuotation",
82+
"mkQuotVar",
8383
Any,
8484
[
8585
makeStrConst ident.Name
@@ -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, "fable_quotation", "mk_let", Any, [ varExpr; valueExpr; bodyExpr ])
94+
Helper.LibCall(com, "fableQuotation", "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, "fable_quotation", "mk_if_then_else", Any, [ guard; thenE; elseE ])
100+
Helper.LibCall(com, "fableQuotation", "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, "fable_quotation", "mk_app", Any, [ acc; argExpr ])
110+
Helper.LibCall(com, "fableQuotation", "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, "fable_quotation", "mk_call", Any, [ instanceExpr; methodExpr; argExprs ])
129+
Helper.LibCall(com, "fableQuotation", "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, "fable_quotation", "mk_sequential", Any, [ firstExpr; restExpr ])
138+
Helper.LibCall(com, "fableQuotation", "mkSequential", Any, [ firstExpr; restExpr ])
139139

140140
| Operation(kind, _tags, _typ, _r) ->
141141
// Represent operations as calls to the operator method
@@ -187,23 +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, "fable_quotation", "mk_call", Any, [ instanceExpr; methodExpr; argExprs ])
190+
Helper.LibCall(com, "fableQuotation", "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 ->
197-
Helper.LibCall(com, "fable_quotation", "mk_tuple_get", Any, [ target; makeIntConst index ])
198-
| UnionTag -> Helper.LibCall(com, "fable_quotation", "mk_union_tag", Any, [ target ])
196+
| TupleIndex index -> Helper.LibCall(com, "fableQuotation", "mkTupleGet", Any, [ target; makeIntConst index ])
197+
| UnionTag -> Helper.LibCall(com, "fableQuotation", "mkUnionTag", Any, [ target ])
199198
| UnionField info ->
200-
Helper.LibCall(com, "fable_quotation", "mk_union_field", Any, [ target; makeIntConst info.FieldIndex ])
201-
| FieldGet info ->
202-
Helper.LibCall(com, "fable_quotation", "mk_field_get", Any, [ target; makeStrConst info.Name ])
199+
Helper.LibCall(com, "fableQuotation", "mkUnionField", Any, [ target; makeIntConst info.FieldIndex ])
200+
| FieldGet info -> Helper.LibCall(com, "fableQuotation", "mkFieldGet", Any, [ target; makeStrConst info.Name ])
203201
| _ ->
204202
// ListHead, ListTail, OptionValue, ExprGet — fall through
205203
let msg = "Unsupported quotation Get kind"
206-
Helper.LibCall(com, "fable_quotation", "mk_value", Any, [ makeStrConst msg; makeStrConst "string" ])
204+
Helper.LibCall(com, "fableQuotation", "mkValue", Any, [ makeStrConst msg; makeStrConst "string" ])
207205

208206
| Set(expr, kind, _typ, value, _r) ->
209207
let target = emitQuotedExpr com expr
@@ -212,12 +210,12 @@ let rec emitQuotedExpr (com: Compiler) (expr: Expr) : Expr =
212210
match kind with
213211
| ValueSet ->
214212
// Mutable variable set: expr is the ident, value is the new value
215-
Helper.LibCall(com, "fable_quotation", "mk_var_set", Any, [ target; valueExpr ])
213+
Helper.LibCall(com, "fableQuotation", "mkVarSet", Any, [ target; valueExpr ])
216214
| FieldSet fieldName ->
217-
Helper.LibCall(com, "fable_quotation", "mk_field_set", Any, [ target; makeStrConst fieldName; valueExpr ])
215+
Helper.LibCall(com, "fableQuotation", "mkFieldSet", Any, [ target; makeStrConst fieldName; valueExpr ])
218216
| _ ->
219217
let msg = "Unsupported quotation Set kind"
220-
Helper.LibCall(com, "fable_quotation", "mk_value", Any, [ makeStrConst msg; makeStrConst "string" ])
218+
Helper.LibCall(com, "fableQuotation", "mkValue", Any, [ makeStrConst msg; makeStrConst "string" ])
221219

222220
| TypeCast(innerExpr, _typ) ->
223221
// Coerce/cast: just emit the inner expression for now
@@ -230,49 +228,48 @@ let rec emitQuotedExpr (com: Compiler) (expr: Expr) : Expr =
230228
| [ ([], body) ] -> emitQuotedExpr com body
231229
| _ ->
232230
let msg = "Unsupported quotation node: DecisionTree"
233-
Helper.LibCall(com, "fable_quotation", "mk_value", Any, [ makeStrConst msg; makeStrConst "string" ])
231+
Helper.LibCall(com, "fableQuotation", "mkValue", Any, [ makeStrConst msg; makeStrConst "string" ])
234232

235233
| DecisionTreeSuccess(idx, boundValues, _typ) ->
236234
match boundValues with
237235
| [] -> emitQuotedExpr com (Value(UnitConstant, None))
238236
| [ single ] -> emitQuotedExpr com single
239237
| _ ->
240238
let msg = "Unsupported quotation node: DecisionTreeSuccess"
241-
Helper.LibCall(com, "fable_quotation", "mk_value", Any, [ makeStrConst msg; makeStrConst "string" ])
239+
Helper.LibCall(com, "fableQuotation", "mkValue", Any, [ makeStrConst msg; makeStrConst "string" ])
242240

243241
| _ ->
244242
// Unsupported node: emit an error value
245243
let msg = $"Unsupported quotation node: %A{expr.GetType().Name}"
246244

247-
Helper.LibCall(com, "fable_quotation", "mk_value", Any, [ makeStrConst msg; makeStrConst "string" ])
245+
Helper.LibCall(com, "fableQuotation", "mkValue", Any, [ makeStrConst msg; makeStrConst "string" ])
248246

249247
and private emitQuotedValue (com: Compiler) (kind: ValueKind) (_r: SourceLocation option) : Expr =
250248
match kind with
251-
| BoolConstant b ->
252-
Helper.LibCall(com, "fable_quotation", "mk_value", Any, [ makeBoolConst b; makeStrConst "bool" ])
249+
| BoolConstant b -> Helper.LibCall(com, "fableQuotation", "mkValue", Any, [ makeBoolConst b; makeStrConst "bool" ])
253250

254251
| NumberConstant(NumberValue.Int32 i, _) ->
255-
Helper.LibCall(com, "fable_quotation", "mk_value", Any, [ makeIntConst i; makeStrConst "int32" ])
252+
Helper.LibCall(com, "fableQuotation", "mkValue", Any, [ makeIntConst i; makeStrConst "int32" ])
256253

257254
| NumberConstant(NumberValue.Float64 f, _) ->
258255
let floatExpr = Value(NumberConstant(NumberValue.Float64 f, NumberInfo.Empty), None)
259-
Helper.LibCall(com, "fable_quotation", "mk_value", Any, [ floatExpr; makeStrConst "float64" ])
256+
Helper.LibCall(com, "fableQuotation", "mkValue", Any, [ floatExpr; makeStrConst "float64" ])
260257

261258
| StringConstant s ->
262-
Helper.LibCall(com, "fable_quotation", "mk_value", Any, [ makeStrConst s; makeStrConst "string" ])
259+
Helper.LibCall(com, "fableQuotation", "mkValue", Any, [ makeStrConst s; makeStrConst "string" ])
263260

264261
| UnitConstant ->
265-
Helper.LibCall(com, "fable_quotation", "mk_value", Any, [ Value(UnitConstant, None); makeStrConst "unit" ])
262+
Helper.LibCall(com, "fableQuotation", "mkValue", Any, [ Value(UnitConstant, None); makeStrConst "unit" ])
266263

267-
| Null _ -> Helper.LibCall(com, "fable_quotation", "mk_value", Any, [ Value(Null Any, None); makeStrConst "null" ])
264+
| Null _ -> Helper.LibCall(com, "fableQuotation", "mkValue", Any, [ Value(Null Any, None); makeStrConst "null" ])
268265

269266
| CharConstant c ->
270-
Helper.LibCall(com, "fable_quotation", "mk_value", Any, [ Value(CharConstant c, None); makeStrConst "char" ])
267+
Helper.LibCall(com, "fableQuotation", "mkValue", Any, [ Value(CharConstant c, None); makeStrConst "char" ])
271268

272269
| NewTuple(values, _isStruct) ->
273270
let emittedValues = values |> List.map (emitQuotedExpr com) |> makeArray Any
274271

275-
Helper.LibCall(com, "fable_quotation", "mk_new_tuple", Any, [ emittedValues ])
272+
Helper.LibCall(com, "fableQuotation", "mkNewTuple", Any, [ emittedValues ])
276273

277274
| NewUnion(values, tag, entRef, _genArgs) ->
278275
let entName =
@@ -284,8 +281,8 @@ and private emitQuotedValue (com: Compiler) (kind: ValueKind) (_r: SourceLocatio
284281

285282
Helper.LibCall(
286283
com,
287-
"fable_quotation",
288-
"mk_new_union",
284+
"fableQuotation",
285+
"mkNewUnion",
289286
Any,
290287
[ makeStrConst entName; makeIntConst tag; emittedValues ]
291288
)
@@ -298,29 +295,28 @@ and private emitQuotedValue (com: Compiler) (kind: ValueKind) (_r: SourceLocatio
298295

299296
let emittedValues = values |> List.map (emitQuotedExpr com) |> makeArray Any
300297

301-
Helper.LibCall(com, "fable_quotation", "mk_new_record", Any, [ fieldNames; emittedValues ])
298+
Helper.LibCall(com, "fableQuotation", "mkNewRecord", Any, [ fieldNames; emittedValues ])
302299

303300
| NewOption(value, _typ, _isStruct) ->
304301
match value with
305302
| Some v ->
306303
let emitted = emitQuotedExpr com v
307-
Helper.LibCall(com, "fable_quotation", "mk_value", Any, [ emitted; makeStrConst "option" ])
304+
Helper.LibCall(com, "fableQuotation", "mkValue", Any, [ emitted; makeStrConst "option" ])
308305
| None ->
309-
Helper.LibCall(com, "fable_quotation", "mk_value", Any, [ Value(Null Any, None); makeStrConst "option" ])
306+
Helper.LibCall(com, "fableQuotation", "mkValue", Any, [ Value(Null Any, None); makeStrConst "option" ])
310307

311308
| NewList(headAndTail, _typ) ->
312309
match headAndTail with
313310
| Some(head, tail) ->
314311
let headExpr = emitQuotedExpr com head
315312
let tailExpr = emitQuotedExpr com tail
316-
Helper.LibCall(com, "fable_quotation", "mk_new_list", Any, [ headExpr; tailExpr ])
317-
| None ->
318-
Helper.LibCall(com, "fable_quotation", "mk_value", Any, [ Value(Null Any, None); makeStrConst "list" ])
313+
Helper.LibCall(com, "fableQuotation", "mkNewList", Any, [ headExpr; tailExpr ])
314+
| None -> Helper.LibCall(com, "fableQuotation", "mkValue", Any, [ Value(Null Any, None); makeStrConst "list" ])
319315

320316
| _ ->
321317
// Fallback for other value kinds
322318
let msg = "Unsupported quotation value"
323-
Helper.LibCall(com, "fable_quotation", "mk_value", Any, [ makeStrConst msg; makeStrConst "string" ])
319+
Helper.LibCall(com, "fableQuotation", "mkValue", Any, [ makeStrConst msg; makeStrConst "string" ])
324320

325321
and private typeToString (t: Type) : string =
326322
match t with

src/Fable.Transforms/Transforms.Util.fs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,8 +1194,15 @@ module AST =
11941194
// Fable-compiled .fs module — use name as-is (no fable_ prefix)
11951195
moduleName
11961196
else
1197-
// JS fallback module name (e.g., "Option" -> "fable_option")
1198-
"fable_" + (moduleName |> Naming.applyCaseRule Fable.Core.CaseRules.SnakeCase)
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
11991206

12001207
com.LibraryDir + "/" + beamModuleName + ".erl"
12011208

0 commit comments

Comments
 (0)