Skip to content

Unnecessary boxing in "let"#21

Closed
vbrankov wants to merge 1 commit intoocaml:trunkfrom
vbrankov:unnecessary-boxing
Closed

Unnecessary boxing in "let"#21
vbrankov wants to merge 1 commit intoocaml:trunkfrom
vbrankov:unnecessary-boxing

Conversation

@vbrankov
Copy link

A let expression is always boxed, regardless of whether it's necessary or not, like in the following example:

let y =
  let z = x +. x in
  z +. z

This change should fix that. OCaml test suite passes. Here's an example OCaml code with its machine translation without and with the change.

let () =
  let x = 0.5 in
  let w =
    let y =
      let z = x +. x in
      z +. z
    in
    y +. y
  in
  let _u = w +. w in ()
camlTest__entry:
    .cfi_startproc
    subq    $8, %rsp
    .cfi_adjust_cfa_offset  8
.L100:
    movsd   .L101(%rip), %xmm0
    movsd   .L101(%rip), %xmm1
    addsd   %xmm0, %xmm1
    movq    $1277, %rbx
    call    caml_alloc3@PLT
.L102:
    leaq    8(%r15), %rax
    movq    %rbx, -8(%rax)
    addsd   %xmm1, %xmm1
    movsd   %xmm1, (%rax)
    movq    $1277, %rbx
    leaq    16(%rax), %rdi
    movq    %rbx, -8(%rdi)
    movsd   (%rax), %xmm0
    addsd   (%rax), %xmm0
    movsd   %xmm0, (%rdi)
    movsd   (%rdi), %xmm0
    addsd   (%rdi), %xmm0
    movq    $1, %rax
    movq    $1, %rax
    addq    $8, %rsp
    .cfi_adjust_cfa_offset  -8
    ret
camlTest__entry:
    .cfi_startproc
.L100:
    movsd   .L101(%rip), %xmm0
    movsd   .L101(%rip), %xmm1
    addsd   %xmm0, %xmm1
    addsd   %xmm1, %xmm1
    addsd   %xmm1, %xmm1
    addsd   %xmm1, %xmm1
    movq    $1, %rax
    movq    $1, %rax
    ret

…ations like:

    let y =
      let z = x +. x in
      z +. z
@alainfrisch
Copy link
Contributor

Thanks! Committed to trunk, rev 14486.

@avsm
Copy link
Member

avsm commented Mar 25, 2014

Closing this as it has been merged to trunk.

@avsm avsm closed this Mar 25, 2014
lpw25 pushed a commit to lpw25/ocaml that referenced this pull request Oct 1, 2014
Always generalize implicits before generalization
@vbrankov vbrankov deleted the unnecessary-boxing branch October 23, 2014 18:32
lpw25 pushed a commit to lpw25/ocaml that referenced this pull request Jan 4, 2016
chenglou pushed a commit to chenglou/ocaml that referenced this pull request Feb 15, 2019
stedolan pushed a commit to stedolan/ocaml that referenced this pull request Feb 20, 2020
…istic

Stw minor gc shortcut opportunistic
lpw25 pushed a commit to lpw25/ocaml that referenced this pull request Oct 12, 2021
Adds allocation modes on arrow types, including mode checking for complex applications (reordered and omitted labelled arguments).

Adds tests for values that are never locally allocated.

Includes a bugfix: let[@stack] at module level was incorrectly accepted.

(Contains bootstrap)
lpw25 pushed a commit to lpw25/ocaml that referenced this pull request Nov 12, 2021
Adds allocation modes on arrow types, including mode checking for complex applications (reordered and omitted labelled arguments).

Adds tests for values that are never locally allocated.

Includes a bugfix: let[@stack] at module level was incorrectly accepted.

(Contains bootstrap)
stedolan pushed a commit to stedolan/ocaml that referenced this pull request May 24, 2022
stedolan added a commit to stedolan/ocaml that referenced this pull request May 24, 2022
173842c Merge flambda-backend changes
ed7eba2 Remove leading space from LINE. (oxcaml/oxcaml#484)
bd61170 Bump magic numbers (ocaml#5)
c50c47d Add CI builds with local allocations enabled
1412792 Move local allocations support behind '-extension local'
6d8e42a Better tail call behaviour in caml_applyN
c7dac3d Typemod: toplevel bindings escape even if no variables are bound
82d6c3e Several fixes for partial application and currying
d05c70c Pprintast support for new local syntax
e0e62fc Typecheck x |> f y as (f y x), not ((f y) x)
d7e34ce Remove autogeneration of @ocaml.curry
b9a0593 Port oxcaml/oxcaml#493
0a872d9 Code review fixes from oxcaml/oxcaml#491
6c168bb Remove local allocation counting
3c6e7f0 Code review fixes from oxcaml/oxcaml#478
bb97207 Rename Lambda.apply_position
a7cb650 Quieten Makefile when runtime dep files are not present
c656dc9 Merge flambda-backend changes
11b5424 Avoid printing double spaces in function argument lists
7751faa Restore locations to Typedtree.{pat,let}_bound_idents_full
e450b6c add build_ocaml_compiler.sexp
0403bb3 Revert PR 9895 to continue installing VERSION
b3447db Ensure new local attributes are namespaced properly
7f213fc Allow empty functions again
8f22ad8 Bugfix: ensure local domain state is initialised
80f54dd Bugfix for Selectgen with regions
e8133a1 Fix external-external signature inclusion
9840051 Bootstrap
d879f23 Merge remote-tracking branch 'jane/local-reviewed' into local-merge
94454f5 Use Local_store for the local allocations ref
54a164c Create fewer regions, according to typechecking (ocaml#59)
1c2479b Merge flambda-backend changes
ce34678 Fix printing of modes in return types
91f2281 Hook mode variable solving into Btype.snapshot/backtrack
54e4b09 Move Alloc_mode and Value_mode to Btype
ff4611e Merge flambda-backend changes
ce62e45 Ensure allocations are initialised, even dead ones
6b6ec5a Fix the alloc.ml test on 32-bit builds
81e9879 Merge flambda-backend changes
40a7f89 Update repo URL for ocaml-jst, and rename script.
0454ee7 Add some new locally-allocating primitives (ocaml#57)
8acdda1 Reset the local stack pointer in exception handlers (ocaml#56)
8dafa98 Improve typing for (||) and (&&) (ocaml#55)
8c64754 Fix make_check_all_arches (ocaml#54)
b50cd45 Allow arguments to primitives to be local even in tail position (ocaml#53)
cad125d Fix modes from or-patterns (ocaml#50)
4efdb72 Fix tailcalls tests with inlining (ocaml#52)
4a795cb Flambda support (ocaml#49)
74722cb Add [@ocaml.principal] and [@ocaml.noprincipal] attributes, and use in oo.mli
6d7d3b8 Ensure that functions are evaluated after their arguments (flambda-backend ocaml#353)
89bda6b Keep Sys.opaque_identity in Cmm and Mach (port upstream PR 9412)
a39126a Fix tailcalls within regions (ocaml#48)
4ac4cfd Fix stdlib manpages build
3a95f5e Merge flambda-backend changes
efe80c9 Add jane/pull-flambda-patches script
fca94c4 Register allocations for Omitted parameter closures (ocaml#47)
103b139 Remove various FIXMEs (ocaml#46)
62ba2c1 Bootstrap
a0062ad Allow local allocations for various primitives (ocaml#43)
7a2165e Allow primitives to be poly-moded (ocaml#43)
2af3f55 Fix a flaky test by refactoring TypePairs (ocaml#10638)
58dd807 Bootstrap
ee3be10 Fix modes in build_apply for partial applications
fe73656 Tweak for evaluation order of labelled partial applications (ocaml#10653)
0527570 Fix caml_modify on local allocations (ocaml#40)
e657e99 Relax modes for `as` patterns (ocaml#42)
f815bf2 Add special mode handling for tuples in matches and let bindings (ocaml#38)
39f1211 Only take the upper bounds of modes associated with allocations (ocaml#37)
aec6fde Interpret arrow types in "local positions" differently
c4f3319 Bootstrap
ff6fdad Add some missing regions
40d586d Bootstrap
66d8110 Switch to a system with 3 modes for values
f2c5a85 Bugfix for Comballoc with local allocations. (ocaml#41)
83bcd09 Fix bug with root scanning during compaction (ocaml#39)
1b5ec83 Track modes in Lambda.lfunction and onwards (ocaml#33)
f1e2e97 Port ocaml#10728
56703cd Port ocaml#10081
eb66785 Support local allocations in i386 and fix amd64 bug (ocaml#31)
c936b19 Disallow local recursive non-functions (ocaml#30)
c7a193a GC support for local allocations (ocaml#29)
8dd7270 Nonlocal fields (ocaml#28)
e19a2f0 Bootstrap
694b9ac Add syntax to the parser for local allocations (ocaml#26)
f183008 Lower initial stack size
918226f Allow local closure allocations (ocaml#27)
2552e7d Introduce mode variables (ocaml#25)
bc41c99 Minor fixes for local allocations (ocaml#24)
a2a4e60 Runtime and compiler support for more local allocations (ocaml#23)
d030554 Typechecking for local allocations (ocaml#21)
9ee2332 Bugfix missing from ocaml#20
02c4cef Retain block-structured local regions until Mach.
86dbe1c amd64: Move stack realloc calls out-of-line
324d218 More typing modes and locking of environments
a4080b8 Initial version of local allocation (unsafe)

git-subtree-dir: ocaml
git-subtree-split: 173842c
stedolan pushed a commit to stedolan/ocaml that referenced this pull request May 24, 2022
ce88833 Merge flambda-backend changes
b7506bb Revert "Cherry-pick of ocaml/ocaml 1eeb0e7 (ocaml#12)"
183f688 Add config option to enable/disable stack allocation (ocaml#22)
ee7c849 If both the type and mode of an ident are wrong, complain about the type. (ocaml#19)
44bade0 Allow submoding during module inclusion checks (ocaml#21)
de3bec9 Add subtyping between arrows of related modes (ocaml#20)
93d8615 Enable the local keywords even when the local extension is off (ocaml#18)
81dd85e Documentation for local allocations
b05519f Fix a GC bug in local stack scanning (ocaml#17)
9f879de Fix __FUNCTION__ (ocaml#15)
a78975e Optimise "include struct ... end" in more cases (ocaml#11134)
b819c66 Cherry-pick of ocaml/ocaml 1eeb0e7 (ocaml#12)
bb363d4 Optimise the allocation of optional arguments (ocaml#11)

git-subtree-dir: ocaml
git-subtree-split: ce88833
lpw25 added a commit to lpw25/ocaml that referenced this pull request Jun 21, 2022
patricoferris pushed a commit to patricoferris/ocaml that referenced this pull request Nov 10, 2022
Adds allocation modes on arrow types, including mode checking for complex applications (reordered and omitted labelled arguments).

Adds tests for values that are never locally allocated.

Includes a bugfix: let[@stack] at module level was incorrectly accepted.

(Contains bootstrap)
sadiqj pushed a commit to sadiqj/ocaml that referenced this pull request Feb 21, 2023
* dune file fix for dependency changes

* Fix test output (duplicated attributes are no longer ignored)

* Refactor checking of flambda-backend-only attrs to match new style
stedolan pushed a commit to stedolan/ocaml that referenced this pull request Mar 21, 2023
* dune file fix for dependency changes

* Fix test output (duplicated attributes are no longer ignored)

* Refactor checking of flambda-backend-only attrs to match new style
stedolan pushed a commit to stedolan/ocaml that referenced this pull request Mar 21, 2023
b11eea1 flambda-backend: Introduce Import_info (ocaml#1036)
bc5b135 flambda-backend: Fix `ocamlobjinfo` on flambda2 .cmx files (ocaml#1029)
c8babbd flambda-backend: Compilation_unit optimisations (ocaml#1035)
e8d3e22 flambda-backend: Use 4.14.0 opam switch for building (includes upgrading ocamlformat to 0.24.1) (ocaml#1030)
eb14a86 flambda-backend: Port PR81 from ocaml-jst (ocaml#1024)
131bc12 flambda-backend: Merge ocaml-jst 2022-12-13 (ocaml#1022)
06c189a flambda-backend: Make stack allocation the default (ocaml#1013)
98debd5 flambda-backend: Initial support for value slots not of value kind (ocaml#946)
deb1714 flambda-backend: Add is_last flag to closinfo words (ocaml#938)
d07fce1 flambda-backend: Disable poll insertion in Configure (ocaml#967)
0f1ce0e flambda-backend: Regenerate ocaml/configure autoconf 2.69 (instead of 2.71) (ocaml#1012)
27132d8 flambda-backend: Fix for spurious typing error related to expanding through functor arguments (ocaml#997)
724fb68 flambda-backend: Use `Compilation_unit.t` instead of `Ident.t` for globals (ocaml#871)
396d5b8 flambda-backend: Add a test for frametable setup in natdynlinked libraries (ocaml#983)
b73ab12 flambda-backend: Fix invocation of `caml_shared_startup` in native dynlink (ocaml#980)
7c7d75a flambda-backend: Fix split_default_wrapper which did not trigger anymore with flambda2 (ocaml#970)
8fb75bd flambda-backend: Port ocaml#11727 and ocaml#11732 (ocaml#965)
fdb7987 flambda-backend: Fix include functor issue after 4.14 merge. (ocaml#948)
9745cdb flambda-backend: Print -dprofile/-dtimings output to stdout like 4.12 (ocaml#943)
5f51f21 flambda-backend: Merge pull request ocaml#932 from mshinwell/4.14-upgrade
841687d flambda-backend: Run make alldepend in ocaml/ (ocaml#936)
72a7658 flambda-backend: Remove reformatting changes only in dynlink/dune (preserving PR889 and adjusting to minimise diff)
6d758cd flambda-backend: Revert whitespace changes in dune files, to match upstream
c86bf6e flambda-backend: Remove duplicate tests for polling
971dbeb flambda-backend: Testsuite fixes
32f8356 flambda-backend: Topeval fix for symbols patch
befea01 flambda-backend: Compilation fixes / rectify merge faults
a84543f flambda-backend: Merge ocaml-jst
8e65056 flambda-backend: Merge ocaml-jst
4d70045 flambda-backend: Remove filename from system frametable (amd64) (ocaml#920)
5e57b7d flambda-backend: Bugfix for runtime frame_descr logic for C frames (ocaml#918)
6423d5e flambda-backend: Merge pull request ocaml#914 from mshinwell/merge-ocaml-jst-2022-10-24
ead605c flambda-backend: Add a missing Extract_exception (ocaml#916)
c8f1481 flambda-backend: Resolve conflicts and add specialise/specialised attributes to Builtin_attributes
cf4d0d3 flambda-backend: Merge fixes (ocaml#21)
c2f742f flambda-backend: Re-enable some tests for Flambda2 (ocaml#881)
3d38d13 flambda-backend: Long frames in frametable (ocaml#797)
85aec7b flambda-backend: Add loop attribute to Builtin_attributes
c0f16e3 flambda-backend: Compilation fixes
90dea23 flambda-backend: Merge flambda-backend/main
5acc6ea flambda-backend: Fixes after merge
e501946 flambda-backend: Merge ocaml-jst
115083b flambda-backend: Merge ocaml-jst
9943b2e flambda-backend: Revert "Revert "Transform tail-recursive functions into recursive continuations (ocaml#893)"" (ocaml#909)
ce339f1 flambda-backend: Fix alloc modes and call kinds for overapplications (ocaml#902)
e6a317c flambda-backend: Revert "Transform tail-recursive functions into recursive continuations (ocaml#893)"
853c488 flambda-backend: Transform tail-recursive functions into recursive continuations (ocaml#893)
5a977e4 flambda-backend: Fix missing End_region primitives on switch arms (ocaml#898)
7fa7f9d flambda-backend: Add missing dependencies to Dune files (ocaml#889)
3cd36f0 flambda-backend: Have Lambda `Pgetglobal` and `Psetglobal` take `Compilation_unit.t` (ocaml#896)
7565915 flambda-backend: [@poll error] attribute (ocaml#745)
9eb9448 flambda-backend: Backport the main safepoints PRs (ocaml#740)
689bdda flambda-backend: Add strict mode for ocamldep (ocaml#892)

git-subtree-dir: ocaml
git-subtree-split: b11eea1
EmileTrotignon pushed a commit to EmileTrotignon/ocaml that referenced this pull request Jan 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants