Skip to content

Feature/avoid function call unnecessarily in ho func#35

Merged
wf001 merged 3 commits into
devfrom
feature/avoid-function-call-unnecessarily-in-ho-func
May 8, 2025
Merged

Feature/avoid function call unnecessarily in ho func#35
wf001 merged 3 commits into
devfrom
feature/avoid-function-call-unnecessarily-in-ho-func

Conversation

@wf001
Copy link
Copy Markdown
Owner

@wf001 wf001 commented May 8, 2025

What’s this PR?

What’s changed?

  • update the node kind of 0-arity function call from nd.var-reference to nd.funcall
(def f::[int] => [int]
 (fn[v]
  (conj v 32)))

(def g::[int] [12, 34, 56])

(def h::[int]
 (fn[]
  [78, 90]))

(def inc::int => int
 (fn[x]
  (+ x 1)))

(def main ::int
  (fn[]
    (let [v ::[int] [42, 64, 90]]
      (prn (f v))
      (prn g)
      (prn h)
      (prn v)
      (prn (map inc [11, 12, 13]))
      )))

before

DEBUG            [.Child]                  file=node.go func=types.indicate line=256
DEBUG            {Kind:"nd.expr", Val:"", Type:<nil>,  Len:0}
DEBUG              {Kind:"nd.libcall", Val:"prn", Type:<nil>,  Len:0}
DEBUG                {Kind:"nd.funccall", Val:"f", Type:<nil>,  Len:0}
DEBUG                  {Kind:"nd.var.reference", Val:"v", Type:<nil>,  Len:0}
DEBUG              {Kind:"nd.libcall", Val:"prn", Type:<nil>,  Len:0}
DEBUG                {Kind:"nd.var.reference", Val:"g", Type:<nil>,  Len:0}
DEBUG              {Kind:"nd.libcall", Val:"prn", Type:<nil>,  Len:0}
DEBUG                {Kind:"nd.var.reference", Val:"h", Type:<nil>,  Len:0}
DEBUG              {Kind:"nd.libcall", Val:"prn", Type:<nil>,  Len:0}
DEBUG                {Kind:"nd.var.reference", Val:"v", Type:<nil>,  Len:0}
DEBUG              {Kind:"nd.libcall", Val:"prn", Type:<nil>,  Len:0}
DEBUG                {Kind:"nd.libcall", Val:"map", Type:<nil>,  Len:0}
DEBUG                  {Kind:"nd.var.reference", Val:"inc", Type:<nil>,  Len:0}
DEBUG                  {Kind:"nd.collection", Val:"", Type:{Value: "vector", ExtendName: "", Child: "{Value: "int", ExtendName: "" }" },  Len:0}
DEBUG                    {Kind:"nd.scalar", Val:"11", Type:{Value: "int", ExtendName: "" },  Len:0}
DEBUG                    {Kind:"nd.scalar", Val:"12", Type:{Value: "int", ExtendName: "" },  Len:0}
DEBUG                    {Kind:"nd.scalar", Val:"13", Type:{Value: "int", ExtendName: "" },  Len:0}

after

DEBUG            [.Child]                  file=node.go func=types.indicate line=257
DEBUG            {Kind:"nd.expr", Val:"", Type:<nil>,  Len:0}
DEBUG              {Kind:"nd.libcall", Val:"prn", Type:<nil>,  Len:0}
DEBUG                {Kind:"nd.funccall", Val:"f", Type:<nil>,  Len:0}
DEBUG                  {Kind:"nd.var.reference", Val:"v", Type:{Value: "vector", ExtendName: "", Child: "{Value: "int", ExtendName: "" }" },  Len:0}
DEBUG              {Kind:"nd.libcall", Val:"prn", Type:<nil>,  Len:0}
DEBUG                {Kind:"nd.var.reference", Val:"g", Type:{Value: "vector", ExtendName: "", Child: "{Value: "int", ExtendName: "" }" },  Len:0}
DEBUG              {Kind:"nd.libcall", Val:"prn", Type:<nil>,  Len:0}
DEBUG                {Kind:"nd.funccall", Val:"h", Type:<nil>,  Len:0}
DEBUG              {Kind:"nd.libcall", Val:"prn", Type:<nil>,  Len:0}
DEBUG                {Kind:"nd.var.reference", Val:"v", Type:{Value: "vector", ExtendName: "", Child: "{Value: "int", ExtendName: "" }" },  Len:0}
DEBUG              {Kind:"nd.libcall", Val:"prn", Type:<nil>,  Len:0}
DEBUG                {Kind:"nd.libcall", Val:"map", Type:<nil>,  Len:0}
DEBUG                  {Kind:"nd.var.reference", Val:"inc", Type:<nil>,  Len:0}
DEBUG                  {Kind:"nd.collection", Val:"", Type:{Value: "vector", ExtendName: "", Child: "{Value: "int", ExtendName: "" }" },  Len:0}
DEBUG                    {Kind:"nd.scalar", Val:"11", Type:{Value: "int", ExtendName: "" },  Len:0}
DEBUG                    {Kind:"nd.scalar", Val:"12", Type:{Value: "int", ExtendName: "" },  Len:0}
DEBUG                    {Kind:"nd.scalar", Val:"13", Type:{Value: "int", ExtendName: "" },  Len:0}
  • avoid function call unnecessarily in high-order func
(def conjw :: double => double
  (fn [x]
    (+ x 1.1)))

(def main :: int
  (fn []
    (prn (map conjw [3.2 5.4]))
    ))
define i32 @main() {
0:
        call void @fn.unnamed.0x14000161170()
        ret i32 0
}

define void @fn.unnamed.0x14000161170() {
fn.entry.0x14000161170.0:
        %0 = call double @fn.conjw() <- remove
        %1 = mul i64 64, 2
        %2 = call i8* @malloc(i64 %1)

Anything else?

Optional: anything reviewers should pay attention to.

@wf001 wf001 merged commit 9feceac into dev May 8, 2025
1 check passed
@wf001 wf001 deleted the feature/avoid-function-call-unnecessarily-in-ho-func branch May 8, 2025 17:41
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.

1 participant