Skip to content

Commit

Permalink
[ysh] Fix '= __builtins__' bug in a different way
Browse files Browse the repository at this point in the history
value::Stdin is a global singleton, so it has no object ID.  That is,
the assertion to prevent HeapTag::Global was correct.

So add a case for value::{Stdin,Interrupted} in the pretty printer.
  • Loading branch information
Andy C committed Nov 2, 2024
1 parent 6bc0ab0 commit ebbcce2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
5 changes: 3 additions & 2 deletions cpp/data_lang.cc
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,9 @@ int HeapValueId(value_asdl::value_t* val) {
// ASDL generates headers with HeapTag::Scanned, but HeapTag::FixedSize would
// also be valid.
ObjHeader* h = ObjHeader::FromObject(val);
DCHECK(h->heap_tag == HeapTag::Global || h->heap_tag == HeapTag::Scanned ||
h->heap_tag == HeapTag::FixedSize);
// Note: value::Stdin is a HeapTag::Global singleton, but we avoid calling it
// on that. Could return -1 for the HeapValueId instead of this assertion?
DCHECK(h->heap_tag == HeapTag::Scanned || h->heap_tag == HeapTag::FixedSize);
#endif

return ObjectId(val);
Expand Down
18 changes: 15 additions & 3 deletions display/pp_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,11 +392,12 @@ def _SparseArray(self, val):

def _Obj(self, obj):
# type: (Obj) -> MeasuredDoc
chain = [] # type: List[MeasuredDoc]
chain = [] # type: List[MeasuredDoc]
cur = obj
while cur is not None:
mdocs = self._DictMdocs(cur.d)
chain.append(self._Surrounded("(", self._Join(mdocs, ",", " "), ")"))
chain.append(
self._Surrounded("(", self._Join(mdocs, ",", " "), ")"))
cur = cur.prototype
if cur is not None:
chain.append(UText(" --> "))
Expand Down Expand Up @@ -430,7 +431,11 @@ def _Value(self, val):
elif case(value_e.Range):
r = cast(value.Range, val)
type_name = self._Styled(self.type_style, UText(ValType(r)))
mdocs = [UText(str(r.lower)), UText("..<"), UText(str(r.upper))]
mdocs = [
UText(str(r.lower)),
UText("..<"),
UText(str(r.upper))
]
return self._SurroundedAndPrefixed("(", type_name, " ",
self._Join(mdocs, "", " "),
")")
Expand Down Expand Up @@ -492,6 +497,13 @@ def _Value(self, val):
self.visiting[heap_id] = False
return result

# Bug fix: these types are GLOBAL singletons in C++. This means
# they have no object ID, so j8.ValueIdString() will CRASH on them.

elif case(value_e.Stdin, value_e.Interrupted):
type_name = self._Styled(self.type_style, UText(ValType(val)))
return _Concat([UText("<"), type_name, UText(">")])

else:
type_name = self._Styled(self.type_style, UText(ValType(val)))
id_str = j8.ValueIdString(val)
Expand Down
5 changes: 4 additions & 1 deletion metrics/source-code.sh
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,10 @@ _overview() {

tools-counts $count "$@"

ls stdlib/*.ysh | $count \
ls stdlib/osh/*.sh | $count \
"OSH stdlib" '' "$@"

ls stdlib/ysh/*.ysh | $count \
"YSH stdlib" '' "$@"

ls pylib/*.py | filter-py | $count \
Expand Down

0 comments on commit ebbcce2

Please sign in to comment.