reactorlabs/rir

support for named indices

開放

#798 建立於 2020年1月24日

 (0 則留言) (0 個反應) (0 位負責人)C++ (19 個分叉)github user discovery
enhancementhelp wanted

倉庫指標

星標
 (61 顆星)
PR 合併指標
 (平均合併 1分鐘) (30 天內合併 1 個 PR)

描述

The description here depends on some type inference inprovements in #797

Reproduce

run with PIR_DEBUG=PrintPirAfterOpt

f <- function() {
  a <- c(1,2,3)
  names(a) <- c("one", "two", "three")
  a['one'] + a['two']
}
f()
f()
f()

Observe that the result contains:

  str$"           %2.4  = LdConst                  [1] "one" 
  real$'<real'>   %2.5  = Extract1_1D        wed   %2.3, %2.4, elided

there are two issues here:

  1. the index of "one" is computed at runtime
  2. the result is tagged, because it has an attribute (ie. a name)

Resolving issue (2) is probably a longterm goal, that needs many changes. but (1) should be approachable.

Possible Solution

Currently our type feedback records if a value has attributes (except dimension attrs of matrix) here. We could extend this to specifically record the names attribute.

If the names attribute is stable, we could speculate on it and compute the index at compile time.

貢獻者指南