Received: from mail-qt1-f194.google.com (mail-qt1-f194.google.com [209.85.160.194]) by mail-b.sr.ht (Postfix) with ESMTPS id 689D0FF10C for <~duangle/scopes@lists.sr.ht>; Sat, 4 Jul 2020 20:06:12 +0000 (UTC) Authentication-Results: mail-b.sr.ht; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=oKpeKACf Received: by mail-qt1-f194.google.com with SMTP id o38so26251219qtf.6 for <~duangle/scopes@lists.sr.ht>; Sat, 04 Jul 2020 13:06:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:subject:to:cc:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=r62jni5BXKmoHmmwsU0AE7SHWT9UEItJv516YQS1dKQ=; b=oKpeKACfDd46gxlKpKxB8jOkMvkCcuRZsQoUfY6Npq2Sz7BUUfWNGN+k1taamFTO3V XZuse/vKlgq/znYEE5uTr9eF/EB9TmccuySVqzgN7iPeztNLSoZGiX1SGDCu7ZuTDpGQ cU7PGHReac6jszS683YE0aXGiPqh8y+53ARwHFJM8FzhNt/3e930lDCW6NxdSCRCoj4k D73pZSoUrJ4kZTdNrGdHDU8SUNG1GMh9OfutarNS3Va8Z6Ii4Klw4Zh2QJMmNMHOy582 GZHxNH1j2cnOj5kJyxu6huYfihnN8xg0SpzbxI29slEjb7McWnE1GDPm5hD8wbkrKcuK P6PQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:subject:to:cc:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=r62jni5BXKmoHmmwsU0AE7SHWT9UEItJv516YQS1dKQ=; b=pt3kdx4V+oc9aVn5UcaU8lnI/i2W5YqS3oW+wg/8t+vlM7mDcgnsfKIpddOaNW/ffF pzha7LrvOHDjf2AAeisFreIq7C+cTANXW9Evm+KR5o86Mh4w+kJE32BFJFElD4Q29zqc 8Z3MnQ82zYUtui1CYS8QFjs/uXczAgmhVFOoOovLqzMVZn3477bMEpEGyOYrE7f6x7kq HOKz6PfUIy9Efd0B2f20fCKKF52b1cG3JNGT2QCBdUPH90xDwixSAxOo2zU5SMbZPQCv fwYZYt46sm4YZPiJ5sW28fK5QA6HOkgtVYwRmAORXtHk/82FwhTzv6z7Vozd987IdjW1 NA3A== X-Gm-Message-State: AOAM533NQJ2G/M80iPyHGR2sszMxmWfwuYEn+UX+CuplmJJuY+ew1L81 Lng1QZgosJlpgWi7KVIh05s= X-Google-Smtp-Source: ABdhPJzMKwswKxZy8Pfhr58sUM2lme2lrzjMChll9QBqihTLjiqD62qi0Vk+WOULwLGqDZHFB52MOg== X-Received: by 2002:aed:2171:: with SMTP id 104mr36492797qtc.22.1593893171917; Sat, 04 Jul 2020 13:06:11 -0700 (PDT) Received: from pop-os ([2804:d59:26a4:c100:d8ad:591f:cc03:16f]) by smtp.gmail.com with ESMTPSA id m20sm12890651qkk.104.2020.07.04.13.06.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Jul 2020 13:06:11 -0700 (PDT) Date: Sat, 04 Jul 2020 15:05:46 -0500 From: Westerbly Snaydley Subject: Re: unexpected behavior with arrays? To: Shawn Walker Cc: ~duangle/scopes@lists.sr.ht Message-Id: In-Reply-To: <71NYCQ.87F07ED5PFH2@gmail.com> References: <71NYCQ.87F07ED5PFH2@gmail.com> X-Mailer: geary/3.36.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable On Sat, Jul 4, 2020 at 14:48, Westerbly Snaydley =20 wrote: >=20 >=20 > On Sat, Jul 4, 2020 at 12:34, Shawn Walker =20 > wrote: >> I guess I=E2=80=99m spoiled by the rust compiler=E2=80=99s reasoning abo= ut=20 >> =7Flifetimes. If I try to use =E2=80=98x=E2=80=99 once the binding has = expired it=20 >> =7Fwon=E2=80=99t let me and tells me why. Here it seems like Scopes sho= uld=20 >> =7Fknow the lifetime of the storage and then could prevent or warn=20 >> about =7Ffurther use. >=20 > Scopes' borrow checker is opt-in, and the core is designed such that=20 > lower level constructs / APIs are not checked. The higher level APIs=20 > on the other hand are built on top of those but with security added=20 > in. In this particular example, it's usually recommended to use the=20 > Array (from Array.sc) data-type instead, which is both bounds and=20 > lifetime checked. Similarly alloca, malloc shouldn't be used directly=20 > (ie. use `local` with a unique type, or a Box for heap). > The bottom line is that in normal usage you will always never deal=20 > with pointers (or use most LLVM intrinsic functions), except when=20 > dealing with external C APIs (in which case you can immediately wrap=20 > in a checked type) or when implementing new language features. > ...This is not to say this couldn't change or be added in, but it's=20 > my understanding that the behaviour is by design. >=20 > Westerbly (radgeRayden) Snaydley. Slight correction: in this particular case it's fine to use plain=20 arrays, I meant it more that it's not recommended to use alloca, and if=20 you avoided that there would be no problem. The unique Array type=20 serves as the complementary solution for when you actually would use=20 dynamically allocated memory (like std::vector, I suppose). Also, I think you need to hit reply all when responding to mailing list=20 emails, as your last one didn't show in the archives. Westerbly (radgeRayden) Snaydley.